changeset: 6380:bb3b01f41ed2
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Aug 12 14:33:17 2014 -0700
link:      http://dev.mutt.org/hg/mutt/rev/bb3b01f41ed2

Fix parse_pub_line to allow an empty User-ID field for a pub record. (see #3564)

A key whose primary uid record has an empty User-ID will result in the
user being unable to use the key to encrypt an email in mutt.  This is
because the mutt functions for key selection iterate through the address
fields of a key for matching against and for displaying to the user.

This change allows a pgp_uid_t record to be created for a pub record
whose User-ID field is blank.  So the key will have one address record,
albeit with a null addr field.

changeset: 6381:9a75aa4bd69e
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Aug 12 14:33:17 2014 -0700
link:      http://dev.mutt.org/hg/mutt/rev/9a75aa4bd69e

Wrap pgp_uid_t->addr in NONULL(). (closes #3564)

The previous patch introduced the possibility for addr to be null.  Mutt
is surprisingly robust against null strings, but there are a few places
that should be wrapped in NONULL().

diffs (83 lines):

diff -r 4909bd9c9149 -r 9a75aa4bd69e gnupgparse.c
--- a/gnupgparse.c      Sat Nov 02 20:12:41 2013 -0700
+++ b/gnupgparse.c      Tue Aug 12 14:33:17 2014 -0700
@@ -120,6 +120,7 @@
 {
   pgp_uid_t *uid = NULL;
   int field = 0, is_uid = 0;
+  int is_pub = 0;
   char *pend, *p;
   int trust = 0;
   int flags = 0;
@@ -144,7 +145,7 @@
     if ((pend = strchr (p, ':')))
       *pend++ = 0;
     field++;
-    if (field > 1 && !*p)
+    if (!*p && (field != 1) && (field != 10))
       continue;
 
     switch (field)
@@ -154,7 +155,7 @@
        dprint (2, (debugfile, "record type: %s\n", p));
 
        if (!mutt_strcmp (p, "pub"))
-         ;
+         is_pub = 1;
        else if (!mutt_strcmp (p, "sub"))
          *is_subkey = 1;
        else if (!mutt_strcmp (p, "sec"))
@@ -280,14 +281,20 @@
         break;
       case 10:                 /* name             */
       {
-       if (!pend || !*p)
-         break;                        /* empty field or no trailing colon */
+        /* Empty field or no trailing colon.
+         * We allow an empty field for a pub record type because it is
+         * possible for a primary uid record to have an empty User-ID
+         * field.  Without any address records, it is not possible to
+         * use the key in mutt.
+         */
+        if (!(pend && (*p || is_pub)))
+         break;
 
        /* ignore user IDs on subkeys */
        if (!is_uid && (*is_subkey && option (OPTPGPIGNORESUB)))
          break;
 
-       dprint (2, (debugfile, "user ID: %s\n", p));
+       dprint (2, (debugfile, "user ID: %s\n", NONULL (p)));
 
        uid = safe_calloc (sizeof (pgp_uid_t), 1);
        fix_uid (p);
diff -r 4909bd9c9149 -r 9a75aa4bd69e pgpkey.c
--- a/pgpkey.c  Sat Nov 02 20:12:41 2013 -0700
+++ b/pgpkey.c  Tue Aug 12 14:33:17 2014 -0700
@@ -228,7 +228,7 @@
       if (!optional)
       {
        snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
-       snprintf (dest, destlen, fmt, uid->addr);
+       snprintf (dest, destlen, fmt, NONULL (uid->addr));
       }
       break;
     case 'a':
@@ -586,7 +586,7 @@
 
     case OP_VIEW_ID:
 
-      mutt_message ("%s", KeyTable[menu->current]->addr);
+      mutt_message ("%s", NONULL (KeyTable[menu->current]->addr));
       break;
 
     case OP_GENERIC_SELECT_ENTRY:
@@ -956,7 +956,7 @@
     for (a = k->address; a; a = a->next)
     {
       dprint (5, (debugfile, "pgp_getkeybystr: matching \"%s\" against key %s, 
\"%s\": ",
-                 p, pgp_keyid (k), a->addr));
+                 p, pgp_keyid (k), NONULL (a->addr)));
       if (!*p || mutt_strcasecmp (p, pgp_keyid (k)) == 0 ||
          (!mutt_strncasecmp (p, "0x", 2) && !mutt_strcasecmp (p + 2, pgp_keyid 
(k))) ||
          (option (OPTPGPLONGIDS) && !mutt_strncasecmp (p, "0x", 2) &&

Reply via email to