2007-02-22 [paul] 2.7.2cvs62
authorColin Leroy <colin@colino.net>
Thu, 22 Feb 2007 12:00:53 +0000 (12:00 +0000)
committerColin Leroy <colin@colino.net>
Thu, 22 Feb 2007 12:00:53 +0000 (12:00 +0000)
* src/plugins/pgpcore/sgpgme.c
* src/plugins/pgpcore/sgpgme.h
* src/plugins/pgpcore/passphrase.c
* src/plugins/pgpinline/pgpinline.c
* src/plugins/pgpmime/pgpmime.c
Fix a leak - gpgme_data_release_and_get_mem
leaks in recent gpgme. Workaround by using
our own function.

ChangeLog
PATCHSETS
configure.ac
src/plugins/pgpcore/passphrase.c
src/plugins/pgpcore/sgpgme.c
src/plugins/pgpcore/sgpgme.h
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/pgpmime.c

index 1f067d5..6bbebce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-02-22 [paul]      2.7.2cvs62
+
+       * src/plugins/pgpcore/sgpgme.c
+       * src/plugins/pgpcore/sgpgme.h
+       * src/plugins/pgpcore/passphrase.c
+       * src/plugins/pgpinline/pgpinline.c
+       * src/plugins/pgpmime/pgpmime.c
+               Fix a leak - gpgme_data_release_and_get_mem
+               leaks in recent gpgme. Workaround by using
+               our own function.
+
 2007-02-22 [paul]      2.7.2cvs61
 
        * src/gtk/quicksearch.c
index bdd4091..aff1c74 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.395.2.284 -r 1.395.2.285 src/summaryview.c;  ) > 2.7.2cvs59.patchset
 ( cvs diff -u -r 1.115.2.137 -r 1.115.2.138 src/main.c;  cvs diff -u -r 1.150.2.92 -r 1.150.2.93 src/procmsg.c;  cvs diff -u -r 1.1.2.62 -r 1.1.2.63 src/gtk/quicksearch.c;  cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/plugins/pgpcore/passphrase.c;  ) > 2.7.2cvs60.patchset
 ( cvs diff -u -r 1.1.2.63 -r 1.1.2.64 src/gtk/quicksearch.c;  ) > 2.7.2cvs61.patchset
+( cvs diff -u -r 1.1.2.24 -r 1.1.2.25 src/plugins/pgpcore/passphrase.c;  cvs diff -u -r 1.1.2.41 -r 1.1.2.42 src/plugins/pgpcore/sgpgme.c;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/plugins/pgpcore/sgpgme.h;  cvs diff -u -r 1.1.2.29 -r 1.1.2.30 src/plugins/pgpinline/pgpinline.c;  cvs diff -u -r 1.1.2.45 -r 1.1.2.46 src/plugins/pgpmime/pgpmime.c;  ) > 2.7.2cvs62.patchset
index f1ef985..a594fc5 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=7
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=61
+EXTRA_VERSION=62
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index b6402e6..ddddbf3 100644 (file)
@@ -315,35 +315,35 @@ gpgme_error_t
 gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint,
         const char *passphrase_hint, int prev_bad, int fd)
 {
-    const char *pass;
+    const char *pass = NULL;
 
     if (prefs_gpg_get_config()->store_passphrase && last_pass && !prev_bad)
-        pass = last_pass;
+        pass = g_strdup(last_pass);
     else {
-    gpgmegtk_set_passphrase_grab (prefs_gpg_get_config()->passphrase_grab);
-    debug_print ("%% requesting passphrase for '%s'\n ", uid_hint);
-    pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad, FALSE);
-    gpgmegtk_free_passphrase();
-    if (!pass) {
-        debug_print ("%% cancel passphrase entry\n");
-        write(fd, "\n", 1);
-        return GPG_ERR_CANCELED;
-    }
-    else {
-        if (prefs_gpg_get_config()->store_passphrase) {
-            last_pass = g_strdup(pass);
+       gpgmegtk_set_passphrase_grab (prefs_gpg_get_config()->passphrase_grab);
+       debug_print ("%% requesting passphrase for '%s'\n ", uid_hint);
+       pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad, FALSE);
+       gpgmegtk_free_passphrase();
+       if (!pass) {
+            debug_print ("%% cancel passphrase entry\n");
+            write(fd, "\n", 1);
+            return GPG_ERR_CANCELED;
+       }
+       else {
+            if (prefs_gpg_get_config()->store_passphrase) {
+               last_pass = g_strdup(pass);
 #ifndef G_PLATFORM_WIN32
-            if (mlock(last_pass, strlen(last_pass)) == -1)
-                debug_print("%% locking passphrase failed\n");
+               if (mlock(last_pass, strlen(last_pass)) == -1)
+                    debug_print("%% locking passphrase failed\n");
 #endif
-            if (prefs_gpg_get_config()->store_passphrase_timeout > 0) {
-                    g_timeout_add(prefs_gpg_get_config()
-                                  ->store_passphrase_timeout*60*1000,
-                                  free_passphrase, NULL);
+               if (prefs_gpg_get_config()->store_passphrase_timeout > 0) {
+                       g_timeout_add(prefs_gpg_get_config()
+                                      ->store_passphrase_timeout*60*1000,
+                                      free_passphrase, NULL);
+               }
             }
-        }
-        debug_print ("%% sending passphrase\n");
-    }
+            debug_print ("%% sending passphrase\n");
+       }
     }
 
 #ifdef G_OS_WIN32
index 918127e..a0cf3c1 100644 (file)
@@ -29,6 +29,8 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -799,4 +801,35 @@ void sgpgme_check_create_key(void)
                prefs_gpg_save_config();
        }       
 }
+
+void *sgpgme_data_release_and_get_mem(gpgme_data_t data, size_t *len)
+{
+       char buf[BUFSIZ];
+       void *result = NULL;
+       ssize_t r = 0;
+       size_t w = 0;
+       
+       if (data == NULL)
+               return NULL;
+       if (len == NULL)
+               return NULL;
+
+       /* I know it's deprecated, but we don't compile with _LARGEFILE */
+       gpgme_data_rewind(data);
+       while ((r = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
+               result = realloc(result, r + w);
+               memcpy(result+w, buf, r);
+               w += r;
+       }
+       
+       *len = w;
+
+       gpgme_data_release(data);
+       if (r < 0) {
+               free(result);
+               *len = 0;
+               return NULL;
+       }
+       return result;
+}
 #endif /* USE_GPGME */
index 03df50a..d03beea 100644 (file)
@@ -48,4 +48,6 @@ gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account);
 void sgpgme_check_create_key(void);
 gboolean sgpgme_has_secret_key(void);
 void sgpgme_create_secret_key(PrefsAccount *account, gboolean ask_create);
+void *sgpgme_data_release_and_get_mem(gpgme_data_t data, size_t *len);
+
 #endif /* SGPGME_H */
index 7ad5bb6..d52e46a 100644 (file)
@@ -439,7 +439,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
                        "\r\n",
                        src_codeset);
        
-       chars = gpgme_data_release_and_get_mem(plain, &len);
+       chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0)
                fwrite(chars, len, 1, dstfp);
 
@@ -585,10 +585,10 @@ static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        }
 
 
-       sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
+       sigcontent = sgpgme_data_release_and_get_mem(gpgsig, &len);
        
        if (sigcontent == NULL || len <= 0) {
-               g_warning("gpgme_data_release_and_get_mem failed");
+               g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Data signing failed, no contents."));
                gpgme_data_release(gpgtext);
                g_free(textstr);
@@ -704,10 +704,10 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
 
        err = gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
 
-       enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
+       enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
 
        if (enccontent == NULL || len <= 0) {
-               g_warning("gpgme_data_release_and_get_mem failed");
+               g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err));
                gpgme_data_release(gpgtext);
                g_free(textstr);
index b28fe04..4e51cd8 100644 (file)
@@ -350,7 +350,7 @@ static MimeInfo *pgpmime_decrypt(MimeInfo *mimeinfo)
 
        fprintf(dstfp, "MIME-Version: 1.0\n");
 
-       chars = gpgme_data_release_and_get_mem(plain, &len);
+       chars = sgpgme_data_release_and_get_mem(plain, &len);
        if (len > 0)
                fwrite(chars, len, 1, dstfp);
        fclose(dstfp);
@@ -530,12 +530,12 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
                return FALSE;
        }
 
-       sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
+       sigcontent = sgpgme_data_release_and_get_mem(gpgsig, &len);
        gpgme_data_release(gpgtext);
        g_free(textstr);
 
        if (sigcontent == NULL || len <= 0) {
-               g_warning("gpgme_data_release_and_get_mem failed");
+               g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Data signing failed, no contents."));
                return FALSE;
        }
@@ -646,12 +646,12 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        
        err = gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
 
-       enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
+       enccontent = sgpgme_data_release_and_get_mem(gpgenc, &len);
        gpgme_data_release(gpgtext);
        g_free(textstr);
 
        if (enccontent == NULL || len <= 0) {
-               g_warning("gpgme_data_release_and_get_mem failed");
+               g_warning("sgpgme_data_release_and_get_mem failed");
                privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err));
                gpgme_release(ctx);
                return FALSE;