[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdepim/enterprise4/kdepim/kleopatra/crypto
From:       Marc Mutz <mutz () kde ! org>
Date:       2010-03-02 13:10:06
Message-ID: 1267535406.226898.14641.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1097932 by mutz:

DecryptVerifyTask: try not to pass NULL to std::string ctors (throws) and try to \
prevent non-GpgME::Exceptions from escaping

Trying to fix kolab/issue4179 (gpg4win).


 M  +55 -5     decryptverifytask.cpp  


--- branches/kdepim/enterprise4/kdepim/kleopatra/crypto/decryptverifytask.cpp \
#1097931:1097932 @@ -89,6 +89,10 @@
 
 namespace {
 
+static Error make_error( const gpg_err_code_t code ) {
+    return Error( gpg_error( code ) );
+}
+
 static AuditLog auditLogFromSender( QObject* sender ) {
     return AuditLog::fromJob( qobject_cast<const Job*>( sender ) );
 }
@@ -112,13 +116,20 @@
 static std::string email( const UserID & uid ) {
 
     if ( uid.parent().protocol() == OpenPGP )
-        return stripAngleBrackets( uid.email() );
+        if ( const char * const email = uid.email() )
+            return stripAngleBrackets( email );
+        else
+            return std::string();
 
     assert( uid.parent().protocol() == CMS );
-    const std::string id = uid.id();
-    if ( !id.empty() && id[0] == '<' )
-        return stripAngleBrackets( id );
-    return DN( uid.id() )["EMAIL"].trimmed().toUtf8().constData();
+
+    if ( const char * const id = uid.id() )
+        if ( *id == '<' )
+            return stripAngleBrackets( id );
+        else
+            return DN( id )["EMAIL"].trimmed().toUtf8().constData();
+    else
+        return std::string();
 }
 
 static Mailbox mailbox( const UserID & uid ) {
@@ -807,6 +818,12 @@
         } catch ( const GpgME::Exception & e ) {
             emitResult( q->fromDecryptResult( e.error(), QString::fromLocal8Bit( \
e.what() ), auditLog ) );  return;
+        } catch ( const std::exception & e ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), auditLog ) ); +    \
return; +        } catch ( ... ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught unknown exception"), auditLog ) ); +            return;
         }
     }
 
@@ -892,7 +909,12 @@
         job->start( d->m_input->ioDevice(), d->m_output->ioDevice() );
     } catch ( const GpgME::Exception & e ) {
         d->emitResult( fromDecryptVerifyResult( e.error(), QString::fromLocal8Bit( \
e.what() ), AuditLog() ) ); +    } catch ( const std::exception & e ) {
+        d->emitResult( fromDecryptVerifyResult( make_error( GPG_ERR_INTERNAL ), \
i18n( "Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), AuditLog() ) ); + \
} catch ( ... ) { +        d->emitResult( fromDecryptVerifyResult( make_error( \
GPG_ERR_INTERNAL ), i18n( "Caught unknown exception" ), AuditLog() ) );  }
+                       
 }
 
 class DecryptTask::Private {
@@ -941,6 +963,12 @@
         } catch ( const GpgME::Exception & e ) {
             emitResult( q->fromDecryptResult( e.error(), QString::fromLocal8Bit( \
e.what() ), auditLog ) );  return;
+        } catch ( const std::exception & e ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), auditLog ) ); +    \
return; +        } catch ( ... ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught unknown exception"), auditLog ) ); +            return;
         }
     }
 
@@ -1027,6 +1055,10 @@
         job->start( d->m_input->ioDevice(), d->m_output->ioDevice() );
     } catch ( const GpgME::Exception & e ) {
         d->emitResult( fromDecryptResult( e.error(), QString::fromLocal8Bit( \
e.what() ), AuditLog() ) ); +    } catch ( const std::exception & e ) {
+        d->emitResult( fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), AuditLog() ) ); +  \
} catch ( ... ) { +        d->emitResult( fromDecryptResult( make_error( \
GPG_ERR_INTERNAL ), i18n("Caught unknown exception"), AuditLog() ) );  }
 }
 
@@ -1076,6 +1108,12 @@
         } catch ( const GpgME::Exception & e ) {
             emitResult( q->fromDecryptResult( e.error(), QString::fromLocal8Bit( \
e.what() ), auditLog ) );  return;
+        } catch ( const std::exception & e ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), auditLog ) ); +    \
return; +        } catch ( ... ) {
+            emitResult( q->fromDecryptResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught unknown exception"), auditLog ) ); +            return;
         }
     }
 
@@ -1161,6 +1199,10 @@
         job->start( d->m_input->ioDevice(), d->m_output ? d->m_output->ioDevice() : \
shared_ptr<QIODevice>() );  } catch ( const GpgME::Exception & e ) {
         d->emitResult( fromVerifyOpaqueResult( e.error(), QString::fromLocal8Bit( \
e.what() ), AuditLog() ) ); +    } catch ( const std::exception & e ) {
+        d->emitResult( fromVerifyOpaqueResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), AuditLog() ) ); +  \
} catch ( ... ) { +        d->emitResult( fromVerifyOpaqueResult( make_error( \
GPG_ERR_INTERNAL ), i18n("Caught unknown exception"), AuditLog() ) );  }
 }
 
@@ -1205,6 +1247,10 @@
         emitResult( q->fromVerifyDetachedResult( result, auditLog ) );
     } catch ( const GpgME::Exception & e ) {
         emitResult( q->fromVerifyDetachedResult( e.error(), QString::fromLocal8Bit( \
e.what() ), auditLog ) ); +    } catch ( const std::exception & e ) {
+        emitResult( q->fromVerifyDetachedResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), auditLog ) ); +    \
} catch ( ... ) { +        emitResult( q->fromVerifyDetachedResult( make_error( \
GPG_ERR_INTERNAL ), i18n("Caught unknown exception"), auditLog ) );  }
 }
 
@@ -1287,6 +1333,10 @@
         job->start( d->m_input->ioDevice(), d->m_signedData->ioDevice() );
     } catch ( const GpgME::Exception & e ) {
         d->emitResult( fromVerifyDetachedResult( e.error(), QString::fromLocal8Bit( \
e.what() ), AuditLog() ) ); +    } catch ( const std::exception & e ) {
+        d->emitResult( fromVerifyDetachedResult( make_error( GPG_ERR_INTERNAL ), \
i18n("Caught exception: %1", QString::fromLocal8Bit( e.what() ) ), AuditLog() ) ); +  \
} catch ( ... ) { +        d->emitResult( fromVerifyDetachedResult( make_error( \
GPG_ERR_INTERNAL ), i18n("Caught unknown exception"), AuditLog() ) );  }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic