]> granicus.if.org Git - neomutt/commitdiff
Actually fix gpgme segfault in create_recipient_set().
authorKevin McCarthy <kevin@8t8.us>
Mon, 17 Oct 2016 18:22:13 +0000 (11:22 -0700)
committerRichard Russon <rich@flatcap.org>
Fri, 28 Oct 2016 10:12:20 +0000 (11:12 +0100)
Changeset 6e44bfa16096 did not fix the segv.  (Sorry, I made the fix
based off a report on IRC but didn't trigger the segv myself: it was
caused by an out-of-tree patch).

The actual problem was that the rset was only resized on a successful
gpgme_get_key().  However, on error, the array still needs to be
NULL-terminated before calling free_recipient_set().

Move the resize so it always takes place.  This obviates the need for
the NULL check added in 6e44bfa16096.

crypt-gpgme.c

index 3dcce46ca6c47800b9fc878cf1392a82148c3078..51d5569b924c76ef76a74a71deb61de1f046dcde 100644 (file)
@@ -673,20 +673,15 @@ static gpgme_key_t *create_recipient_set (const char *keylist,
            else
              err = gpgme_get_key (context, buf, &key, 0);
 
+            safe_realloc (&rset, sizeof (*rset) * (rset_n + 1));
            if (! err)
-             {
-               safe_realloc (&rset, sizeof (*rset) * (rset_n + 1));
-               rset[rset_n++] = key;
-             }
+              rset[rset_n++] = key;
            else
              {
                mutt_error (_("error adding recipient `%s': %s\n"),
                            buf, gpgme_strerror (err));
-                if (rset)
-                  {
-                    rset[rset_n] = NULL;
-                    free_recipient_set (&rset);
-                  }
+                rset[rset_n] = NULL;
+                free_recipient_set (&rset);
                gpgme_release (context);
                return NULL;
              }