From: Kevin McCarthy Date: Fri, 7 Dec 2018 03:22:59 +0000 (-0800) Subject: Fix classic gpg date parsing in list-keys. X-Git-Tag: mutt-1-11-2-rel~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59625f545d2e8975c335b79cfc9d5b0d26b61f98;p=mutt Fix classic gpg date parsing in list-keys. GnuPG changed the format of their --with-colons output in 2.0.10. Dates are now seconds since epoch. Update the parse_pub_line() code to detect the new format. The GnuPG changes also separated pub and the first uid. Since mutt allows an empty uid field, the output is a bit less friendly now, with an initial key without an uid. I think that's acceptable, but eventually we'll want to change the parsing behavior. --- diff --git a/gnupgparse.c b/gnupgparse.c index fd754a00..9a2e0cb7 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -246,37 +246,46 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) } case 6: /* timestamp (1998-02-28) */ { - char tstr[11]; - struct tm time; - dprint (2, (debugfile, "time stamp: %s\n", p)); - if (!p) - break; - time.tm_sec = 0; - time.tm_min = 0; - time.tm_hour = 12; - strncpy (tstr, p, 11); - tstr[4] = '\0'; - tstr[7] = '\0'; - if (mutt_atoi (tstr, &time.tm_year) < 0) - { - p = tstr; - goto bail; - } - time.tm_year -= 1900; - if (mutt_atoi (tstr+5, &time.tm_mon) < 0) - { - p = tstr+5; - goto bail; - } - time.tm_mon -= 1; - if (mutt_atoi (tstr+8, &time.tm_mday) < 0) - { - p = tstr+8; - goto bail; - } - tmp.gen_time = mutt_mktime (&time, 0); + if (strchr (p, '-')) /* gpg pre-2.0.10 used format (yyyy-mm-dd) */ + { + char tstr[11]; + struct tm time; + + time.tm_sec = 0; + time.tm_min = 0; + time.tm_hour = 12; + strncpy (tstr, p, 11); + tstr[4] = '\0'; + tstr[7] = '\0'; + if (mutt_atoi (tstr, &time.tm_year) < 0) + { + p = tstr; + goto bail; + } + time.tm_year -= 1900; + if (mutt_atoi (tstr+5, &time.tm_mon) < 0) + { + p = tstr+5; + goto bail; + } + time.tm_mon -= 1; + if (mutt_atoi (tstr+8, &time.tm_mday) < 0) + { + p = tstr+8; + goto bail; + } + tmp.gen_time = mutt_mktime (&time, 0); + } + else /* gpg 2.0.10+ uses seconds since 1970-01-01 */ + { + unsigned long long secs; + + if (mutt_atoull (p, &secs) < 0) + goto bail; + tmp.gen_time = (time_t)secs; + } break; } case 7: /* valid for n days */