[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mutt-dev
Subject:    [PATCH 1 of 2] Fix parse_pub_line to allow an empty User-ID field for a pub record
From:       "Kevin J. McCarthy" <kevin () 8t8 ! us>
Date:       2013-04-11 1:22:05
Message-ID: 6eb6a30cad1c28156f1f.1365643325 () zaogao ! lan
[Download RAW message or body]

This is a fix for Ticket #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.


 gnupgparse.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)



[Attachment #3 (text/x-patch)]

# HG changeset patch
# User Kevin McCarthy <kevin@8t8.us>
# Date 1365627638 25200
# Branch HEAD
# Node ID 6eb6a30cad1c28156f1f91394926947a1bab5cfb
# Parent  d498f0e91914ac060661661d25d3d2eb2dcba39f
Fix parse_pub_line to allow an empty User-ID field for a pub record.

This is a fix for Ticket #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.

diff --git a/gnupgparse.c b/gnupgparse.c
--- a/gnupgparse.c
+++ b/gnupgparse.c
@@ -115,16 +115,17 @@
     iconv_close (cd);
   }
 }
 
 static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k)
 {
   pgp_uid_t *uid = NULL;
   int field = 0, is_uid = 0;
+  int is_pub = 0;
   char *pend, *p;
   int trust = 0;
   int flags = 0;
   struct pgp_keyinfo tmp;
 
   *is_subkey = 0;
   if (!*buf)
     return NULL;
@@ -139,27 +140,27 @@
 
   dprint (2, (debugfile, "parse_pub_line: buf = `%s'\n", buf));
 
   for (p = buf; p; p = pend)
   {
     if ((pend = strchr (p, ':')))
       *pend++ = 0;
     field++;
-    if (field > 1 && !*p)
+    if (!*p && (field != 1) && (field != 10))
       continue;
 
     switch (field)
     {
       case 1:			/* record type */
       {
 	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"))
 	  ;
 	else if (!mutt_strcmp (p, "ssb"))
 	  *is_subkey = 1;
 	else if (!mutt_strcmp (p, "uid"))
 	  is_uid = 1;
@@ -275,18 +276,24 @@
       case 7:			/* valid for n days */
         break;
       case 8:			/* Local id         */
         break;
       case 9:			/* ownertrust       */
         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));
 
 	uid = safe_calloc (sizeof (pgp_uid_t), 1);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic