From 835a3b1e7ffaca3aabd6fab9b72455be4319cbc4 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 12 Aug 2014 14:33:17 -0700 Subject: 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. --- gnupgparse.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gnupgparse.c') diff --git a/gnupgparse.c b/gnupgparse.c index 9de18ebd..9abd0360 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -120,6 +120,7 @@ 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; @@ -144,7 +145,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) if ((pend = strchr (p, ':'))) *pend++ = 0; field++; - if (field > 1 && !*p) + if (!*p && (field != 1) && (field != 10)) continue; switch (field) @@ -154,7 +155,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) 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,8 +281,14 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) 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))) -- cgit v1.2.3