[git] GpgOL - branch, master, updated. gpgol-1.1.3-47-ge5f2b3f

by Andre Heinecke cvs at cvs.gnupg.org
Thu Aug 1 15:26:13 CEST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG extension for MS Outlook".

The branch, master has been updated
       via  e5f2b3f718ab56c1ecc0528d9117cbdd953815f6 (commit)
       via  bce68bff2375e9a2a756074aade51542a341d7e2 (commit)
      from  1b5a49b6039d86989f5154ea0fd6e45d9c912d37 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e5f2b3f718ab56c1ecc0528d9117cbdd953815f6
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Aug 1 12:55:33 2013 +0000

    Fix accessing uninitialized memory
    
        When called to decrypt the full body the wordApplication,
        wordEditor and selection would be uninitalized and
        but when they are not NULL they would still be released in
        the end.
    
        * src/ribbon-callbacks.cpp (decryptInspector): Initialize
        dispatcher pointers.

diff --git a/src/ribbon-callbacks.cpp b/src/ribbon-callbacks.cpp
index 1f0ac46..529cdf2 100644
--- a/src/ribbon-callbacks.cpp
+++ b/src/ribbon-callbacks.cpp
@@ -445,11 +445,11 @@ decryptAttachments (LPDISPATCH ctrl)
 HRESULT
 decryptInspector (LPDISPATCH ctrl, int flags)
 {
-  LPDISPATCH context;
-  LPDISPATCH selection;
-  LPDISPATCH wordEditor;
-  LPDISPATCH mailItem;
-  LPDISPATCH wordApplication;
+  LPDISPATCH context = NULL;
+  LPDISPATCH selection = NULL;
+  LPDISPATCH wordEditor = NULL;
+  LPDISPATCH mailItem = NULL;
+  LPDISPATCH wordApplication = NULL;
 
   struct sink_s decsinkmem;
   sink_t decsink = &decsinkmem;

commit bce68bff2375e9a2a756074aade51542a341d7e2
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Jul 31 14:27:32 2013 +0000

    Factor out recipient lookup and some cleanups
    
        * src/oomhelp.cpp, src/oomhelp.h (get_oom_recipients): New.
        * src/ribbon-callbacks.cpp (encrypt_inspector): Move out
        recipient handling code. Fix indentation.
        (decrypt_inspector): Clean up some comments.

diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index 73270f2..21be27f 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -789,3 +789,38 @@ get_oom_context_window (LPDISPATCH context)
   return ret;
 }
 
+/* Gets a malloced NULL terminated array of recipent strings from
+   an OOM recipients Object. */
+char **
+get_oom_recipients (LPDISPATCH recipients)
+{
+  int recipientsCnt = get_oom_int (recipients, "Count");
+  char **recipientAddrs = NULL;
+  int i;
+
+  if (!recipientsCnt)
+    {
+      return NULL;
+    }
+
+  /* Get the recipients */
+  recipientAddrs = (char**) xmalloc((recipientsCnt + 1) * sizeof(char*));
+  recipientAddrs[recipientsCnt] = NULL;
+  for (i = 1; i <= recipientsCnt; i++)
+    {
+      char buf[16];
+      LPDISPATCH recipient;
+      snprintf (buf, sizeof (buf), "Item(%i)", i);
+      recipient = get_oom_object (recipients, buf);
+      if (!recipient)
+        {
+          /* Should be impossible */
+          recipientAddrs[i-1] = NULL;
+          log_error ("%s:%s: could not find Item %i;",
+                     SRCNAME, __func__, i);
+          break;
+        }
+      recipientAddrs[i-1] = get_oom_string (recipient, "Address");
+    }
+  return recipientAddrs;
+}
diff --git a/src/oomhelp.h b/src/oomhelp.h
index 1f62cbf..231c27d 100644
--- a/src/oomhelp.h
+++ b/src/oomhelp.h
@@ -121,6 +121,10 @@ void del_oom_button (LPDISPATCH button);
 /* Get the HWND of the active window in the current context */
 HWND get_oom_context_window (LPDISPATCH context);
 
+/* Get the address of the recipients as string list */
+char **
+get_oom_recipients (LPDISPATCH recipients);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/ribbon-callbacks.cpp b/src/ribbon-callbacks.cpp
index 2b6d809..1f0ac46 100644
--- a/src/ribbon-callbacks.cpp
+++ b/src/ribbon-callbacks.cpp
@@ -81,12 +81,12 @@ encryptInspector (LPDISPATCH ctrl, int flags)
   struct sink_s sinkmem;
   sink_t sink = &sinkmem;
   char* senderAddr = NULL;
+  char** recipientAddrs = NULL;
   LPSTREAM tmpstream = NULL;
   engine_filter_t filter = NULL;
   char* plaintext = NULL;
   int rc = 0;
   HRESULT hr;
-  int recipientsCnt;
   HWND curWindow;
   protocol_t protocol;
   unsigned int session_number;
@@ -128,7 +128,6 @@ encryptInspector (LPDISPATCH ctrl, int flags)
 
       if (!plaintext || strlen (plaintext) <= 1)
         {
-          /* TODO more usable if we just use all text in this case? */
           MessageBox (NULL,
                       _("Please select text to encrypt."),
                       _("GpgOL"),
@@ -141,7 +140,6 @@ encryptInspector (LPDISPATCH ctrl, int flags)
       plaintext = get_oom_string (mailItem, "Body");
       if (!plaintext || strlen (plaintext) <= 1)
         {
-          /* TODO more usable if we just use all text in this case? */
           MessageBox (NULL,
                       _("Textbody empty."),
                       _("GpgOL"),
@@ -169,9 +167,9 @@ encryptInspector (LPDISPATCH ctrl, int flags)
 
   senderAddr = get_oom_string (sender, "Address");
 
-  recipientsCnt = get_oom_int (recipients, "Count");
+  recipientAddrs = get_oom_recipients (recipients);
 
-  if (!recipientsCnt)
+  if (!recipientAddrs || !(*recipientAddrs))
     {
       MessageBox (NULL,
                   _("Please add at least one recipent."),
@@ -180,92 +178,64 @@ encryptInspector (LPDISPATCH ctrl, int flags)
       goto failure;
     }
 
-  {
-    /* Get the recipients */
-    char *recipientAddrs[recipientsCnt + 1];
-    recipientAddrs[recipientsCnt] = NULL;
-    for (i = 1; i <= recipientsCnt; i++)
-      {
-        char buf[16];
-        LPDISPATCH recipient;
-        snprintf (buf, sizeof (buf), "Item(%i)", i);
-        recipient = get_oom_object (recipients, buf);
-        if (!recipient)
-          {
-            /* Should be impossible */
-            recipientAddrs[i-1] = NULL;
-            log_error ("%s:%s: could not find Item %i;",
-                       SRCNAME, __func__, i);
-            break;
-          }
-        recipientAddrs[i-1] = get_oom_string (recipient, "Address");
-      }
-
-    /* Not lets prepare our encryption */
-    session_number = engine_new_session_number ();
+  /* Now lets prepare our encryption */
+  session_number = engine_new_session_number ();
 
-    /* Prepare the encryption sink */
+  /* Prepare the encryption sink */
 
-    if (engine_create_filter (&filter, write_buffer_for_cb, sink))
-      {
-        for (i = 0; i < recipientsCnt; i++)
-          xfree (recipientAddrs[i]);
-        goto failure;
-      }
+  if (engine_create_filter (&filter, write_buffer_for_cb, sink))
+    {
+      goto failure;
+    }
 
-    encsink->cb_data = filter;
-    encsink->writefnc = sink_encryption_write;
+  encsink->cb_data = filter;
+  encsink->writefnc = sink_encryption_write;
 
-    engine_set_session_number (filter, session_number);
-    engine_set_session_title (filter, _("GpgOL"));
+  engine_set_session_number (filter, session_number);
+  engine_set_session_title (filter, _("GpgOL"));
 
-    if ((rc=engine_encrypt_prepare (filter, curWindow,
-                                    PROTOCOL_UNKNOWN,
-                                    0 /* ENGINE_FLAG_SIGN_FOLLOWS */,
-                                    senderAddr, recipientAddrs, &protocol)))
-      {
-        for (i = 0; i < recipientsCnt; i++)
-          xfree (recipientAddrs[i]);
-        log_error ("%s:%s: engine encrypt prepare failed : %s",
-                   SRCNAME, __func__, gpg_strerror (rc));
-        goto failure;
-      }
-    for (i = 0; i < recipientsCnt; i++)
-      xfree (recipientAddrs[i]);
+  if ((rc=engine_encrypt_prepare (filter, curWindow,
+                                  PROTOCOL_UNKNOWN,
+                                  0 /* ENGINE_FLAG_SIGN_FOLLOWS */,
+                                  senderAddr, recipientAddrs, &protocol)))
+    {
+      log_error ("%s:%s: engine encrypt prepare failed : %s",
+                 SRCNAME, __func__, gpg_strerror (rc));
+      goto failure;
+    }
 
-    /* lets go */
+  /* lets go */
 
-    if ((rc=engine_encrypt_start (filter, 0)))
-      {
-        log_error ("%s:%s: engine encrypt start failed: %s",
-                   SRCNAME, __func__, gpg_strerror (rc));
-        goto failure;
-      }
+  if ((rc=engine_encrypt_start (filter, 0)))
+    {
+      log_error ("%s:%s: engine encrypt start failed: %s",
+                 SRCNAME, __func__, gpg_strerror (rc));
+      goto failure;
+    }
 
-    /* Write the text in the encryption sink. */
-    rc = write_buffer (encsink, plaintext, strlen (plaintext));
+  /* Write the text in the encryption sink. */
+  rc = write_buffer (encsink, plaintext, strlen (plaintext));
 
-    if (rc)
-      {
-        log_error ("%s:%s: writing tmpstream to encsink failed: %s",
-                   SRCNAME, __func__, gpg_strerror (rc));
-        goto failure;
-      }
-    /* Flush the encryption sink and wait for the encryption to get
-       ready.  */
-    if ((rc = write_buffer (encsink, NULL, 0)))
-      goto failure;
-    if ((rc = engine_wait (filter)))
+  if (rc)
+    {
+      log_error ("%s:%s: writing tmpstream to encsink failed: %s",
+                 SRCNAME, __func__, gpg_strerror (rc));
       goto failure;
-    filter = NULL; /* Not valid anymore.  */
-    encsink->cb_data = NULL; /* Not needed anymore.  */
+    }
+  /* Flush the encryption sink and wait for the encryption to get
+     ready.  */
+  if ((rc = write_buffer (encsink, NULL, 0)))
+    goto failure;
+  if ((rc = engine_wait (filter)))
+    goto failure;
+  filter = NULL; /* Not valid anymore.  */
+  encsink->cb_data = NULL; /* Not needed anymore.  */
 
-    if (!sink->enc_counter)
-      {
-        log_debug ("%s:%s: nothing received from engine", SRCNAME, __func__);
-        goto failure;
-      }
-  }
+  if (!sink->enc_counter)
+    {
+      log_debug ("%s:%s: nothing received from engine", SRCNAME, __func__);
+      goto failure;
+    }
 
   /* Check the size of the encrypted data */
   tmpstream->Stat (&tmpStat, 0);
@@ -344,7 +314,7 @@ encryptInspector (LPDISPATCH ctrl, int flags)
       }
   }
 
- failure:
+failure:
   if (rc)
     log_debug ("%s:%s: failed rc=%d (%s) <%s>", SRCNAME, __func__, rc,
                gpg_strerror (rc), gpg_strsource (rc));
@@ -358,6 +328,11 @@ encryptInspector (LPDISPATCH ctrl, int flags)
   RELDISP(tmpstream);
   xfree (plaintext);
   xfree (senderAddr);
+  while (recipientAddrs && *recipientAddrs)
+  {
+    xfree (*recipientAddrs++);
+  }
+  xfree (recipientAddrs);
 
   return S_OK;
 }
@@ -610,7 +585,7 @@ decryptInspector (LPDISPATCH ctrl, int flags)
   /* Write the text in the decryption sink. */
   rc = write_buffer (decsink, encData, encDataLen);
 
-  /* Flush the decryption sink and wait for the encryption to get
+  /* Flush the decryption sink and wait for the decryption to get
      ready.  */
   if ((rc = write_buffer (decsink, NULL, 0)))
     goto failure;
@@ -635,7 +610,7 @@ decryptInspector (LPDISPATCH ctrl, int flags)
       goto failure;
     }
 
-  /* Copy the encrypted stream to the message editor.  */
+  /* Copy the decrypted stream to the message editor.  */
   {
     LARGE_INTEGER off;
     ULONG nread;
@@ -660,7 +635,7 @@ decryptInspector (LPDISPATCH ctrl, int flags)
       }
     if (strlen (buffer) > 1)
       {
-        /* Now replace the crypto data with the encData or show it
+        /* Now replace the crypto data with the decrypted data or show it
         somehow.*/
         int err;
         if (flags & DECRYPT_INSPECTOR_SELECTION)

-----------------------------------------------------------------------

Summary of changes:
 src/oomhelp.cpp          |   35 +++++++++++
 src/oomhelp.h            |    4 +
 src/ribbon-callbacks.cpp |  153 +++++++++++++++++++---------------------------
 3 files changed, 103 insertions(+), 89 deletions(-)


hooks/post-receive
-- 
GnuPG extension for MS Outlook
http://git.gnupg.org




More information about the Gnupg-commits mailing list