[svn] GpgOL - r279 - in trunk: po src

svn author wk cvs at cvs.gnupg.org
Mon Oct 27 19:20:23 CET 2008


Author: wk
Date: 2008-10-27 19:20:23 +0100 (Mon, 27 Oct 2008)
New Revision: 279

Modified:
   trunk/po/de.po
   trunk/po/sv.po
   trunk/src/ChangeLog
   trunk/src/message.cpp
   trunk/src/mimemaker.c
Log:
Better checks for empty messages.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-10-27 17:16:06 UTC (rev 278)
+++ trunk/src/ChangeLog	2008-10-27 18:20:23 UTC (rev 279)
@@ -1,5 +1,14 @@
 2008-10-27  Werner Koch  <wk at g10code.com>
 
+	* mimemaker.c (mime_encrypt): Check for an empty message before
+	creating the filter.  Return a suitable error code.
+	(do_mime_sign): Ditto.
+	(mime_sign_encrypt): Ditto.
+	(mime_sign): Return an error code.
+	* message.cpp (sign_encrypt): Show an error message for empty
+	messages.
+	(message_sign): Ditto.
+
 	* olflange.cpp (install_forms): Add gpgol-cs.
 
 	* mapihelp.cpp (get_internetcharsetbody_tag): New.

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/sv.po  [not shown]
Modified: trunk/src/message.cpp
===================================================================
--- trunk/src/message.cpp	2008-10-27 17:16:06 UTC (rev 278)
+++ trunk/src/message.cpp	2008-10-27 18:20:23 UTC (rev 279)
@@ -1236,8 +1236,14 @@
         err = mime_sign_encrypt (message, hwnd, protocol, recipients);
       else
         err = mime_encrypt (message, hwnd, protocol, recipients);
-      if (err && opt.enable_debug)
+      if (gpg_err_code (err) == GPG_ERR_NO_DATA)
         {
+          MessageBox (hwnd, _("Encrypting or signing an empty message "
+                              "is not possible."),
+                      "GpgOL", MB_ICONERROR|MB_OK);
+        }
+      else if (err && opt.enable_debug)
+        {
           char buf[200];
           
           snprintf (buf, sizeof buf,
@@ -1257,8 +1263,14 @@
   gpg_error_t err;
 
   err = mime_sign (message, hwnd, protocol);
-  if (err && opt.enable_debug)
+  if (gpg_err_code (err) == GPG_ERR_NO_DATA)
     {
+      MessageBox (hwnd, _("Encrypting or signing an empty message "
+                          "is not possible."),
+                  "GpgOL", MB_ICONERROR|MB_OK);
+    }
+  else if (err && opt.enable_debug)
+    {
       char buf[200];
       
       snprintf (buf, sizeof buf,

Modified: trunk/src/mimemaker.c
===================================================================
--- trunk/src/mimemaker.c	2008-10-27 17:16:06 UTC (rev 278)
+++ trunk/src/mimemaker.c	2008-10-27 18:20:23 UTC (rev 279)
@@ -1127,7 +1127,7 @@
 {
   int result = -1;
   int rc;
-  LPATTACH attach;
+  LPATTACH attach = NULL;
   struct sink_s sinkmem;
   sink_t sink = &sinkmem;
   struct sink_s hashsinkmem;
@@ -1138,7 +1138,7 @@
   char *body = NULL;
   int n_att_usable;
   char top_header[BOUNDARYSIZE+200];
-  engine_filter_t filter;
+  engine_filter_t filter = NULL;
   struct databuf_s sigbuffer;
 
   *r_att_table = NULL;
@@ -1159,6 +1159,22 @@
         return -1;
     }
 
+  /* Get the attachment info and the body.  */
+  body = mapi_get_body (message, NULL);
+  if (body && !*body)
+    {
+      xfree (body);
+      body = NULL;
+    }
+  att_table = mapi_create_attach_table (message, 0);
+  n_att_usable = count_usable_attachments (att_table);
+  if (!n_att_usable && !body)
+    {
+      log_debug ("%s:%s: can't sign an empty message\n", SRCNAME, __func__);
+      result = gpg_error (GPG_ERR_NO_DATA);
+      goto failure;
+    }
+
   /* Prepare the signing. */
   if (engine_create_filter (&filter, collect_signature, &sigbuffer))
     goto failure;
@@ -1174,21 +1190,6 @@
     }
 
 
-  /* Get the attachment info and the body.  */
-  body = mapi_get_body (message, NULL);
-  if (body && !*body)
-    {
-      xfree (body);
-      body = NULL;
-    }
-  att_table = mapi_create_attach_table (message, 0);
-  n_att_usable = count_usable_attachments (att_table);
-  if (!n_att_usable && !body)
-    {
-      log_debug ("%s:%s: can't sign an empty message\n", SRCNAME, __func__);
-      goto failure;
-    }
-
   /* Write the top header.  */
   generate_boundary (boundary);
   create_top_signing_header (top_header, sizeof top_header,
@@ -1360,7 +1361,8 @@
   int result = -1;
   mapi_attach_item_t *att_table;
 
-  if (!do_mime_sign (message, hwnd, protocol, &att_table, 0))
+  result = do_mime_sign (message, hwnd, protocol, &att_table, 0);
+  if (!result)
     {
       if (!finalize_message (message, att_table, protocol, 0))
         result = 0;
@@ -1557,7 +1559,7 @@
   mapi_attach_item_t *att_table = NULL;
   char *body = NULL;
   int n_att_usable;
-  engine_filter_t filter;
+  engine_filter_t filter = NULL;
 
   memset (sink, 0, sizeof *sink);
   memset (encsink, 0, sizeof *encsink);
@@ -1566,6 +1568,27 @@
   if (!attach)
     return -1;
 
+  /* Get the attachment info and the body.  We need to do this before
+     creating the engine's filter sue problem sending the cancel to
+     the engine with nothing for the engine to process.  This is
+     actually a bug in our engine code but we better avoid triggering
+     this bug because the engine sometimes hangs.  Fixme: Needs a
+     proper fix. */
+  body = mapi_get_body (message, NULL);
+  if (body && !*body)
+    {
+      xfree (body);
+      body = NULL;
+    }
+  att_table = mapi_create_attach_table (message, 0);
+  n_att_usable = count_usable_attachments (att_table);
+  if (!n_att_usable && !body)
+    {
+      log_debug ("%s:%s: can't encrypt an empty message\n", SRCNAME, __func__);
+      result = gpg_error (GPG_ERR_NO_DATA);
+      goto failure;
+    }
+
   /* Prepare the encryption.  We do this early as it is quite common
      that some recipient keys are not available and thus the
      encryption will fail early. */
@@ -1580,21 +1603,6 @@
   if (protocol == PROTOCOL_UNKNOWN)
     goto failure;
 
-  /* Get the attachment info and the body.  */
-  body = mapi_get_body (message, NULL);
-  if (body && !*body)
-    {
-      xfree (body);
-      body = NULL;
-    }
-  att_table = mapi_create_attach_table (message, 0);
-  n_att_usable = count_usable_attachments (att_table);
-  if (!n_att_usable && !body)
-    {
-      log_debug ("%s:%s: can't encrypt an empty message\n", SRCNAME, __func__);
-      goto failure;
-    }
-
   /* Write the top header.  */
   rc = create_top_encryption_header (sink, protocol, boundary);
   if (rc)
@@ -1689,7 +1697,7 @@
   sink_t tmpsink = &tmpsinkmem;
   char boundary[BOUNDARYSIZE+1];
   mapi_attach_item_t *att_table = NULL;
-  engine_filter_t filter;
+  engine_filter_t filter = NULL;
 
   memset (sink, 0, sizeof *sink);
   memset (encsink, 0, sizeof *encsink);
@@ -1699,6 +1707,37 @@
   if (!attach)
     return -1;
 
+  /* First check that we are not rying to process an empty message
+     which might lock up our engine.  Unfortunately we need to
+     duplicate the code we use in do_mime_sign here.  FIXME: The
+     engine should be fixed instead of using such a workaround.  */
+  {
+    char *body;
+
+    body = mapi_get_body (message, NULL);
+    if (body && !*body)
+    {
+      xfree (body);
+      body = NULL;
+    }
+    att_table = mapi_create_attach_table (message, 0);
+    if (!count_usable_attachments (att_table) && !body)
+      result = gpg_error (GPG_ERR_NO_DATA);
+    xfree (body);
+    if (att_table)
+      {
+        mapi_release_attach_table (att_table);
+        att_table = NULL;
+      }
+    if (gpg_err_code (result) == GPG_ERR_NO_DATA)
+      {
+        log_debug ("%s:%s: can't sign+encrypt an empty message\n",
+                   SRCNAME, __func__);
+        goto failure;
+      }
+  }
+
+
   /* Create a temporary sink to construct the signed data.  */ 
   hr = OpenStreamOnFile (MAPIAllocateBuffer, MAPIFreeBuffer,
                          (SOF_UNIQUEFILENAME | STGM_DELETEONRELEASE




More information about the Gnupg-commits mailing list