gpg: Fix regression in option "self-sigs-only".
authorWerner Koch <wk@gnupg.org>
Tue, 9 Jul 2019 09:07:35 +0000 (11:07 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Thu, 22 Aug 2019 19:11:59 +0000 (20:11 +0100)
* g10/import.c (read_block): Make sure KEYID is availabale also on a
pending packet.
--

Reported-by: Phil Pennock
Fixes-commit: adb120e663fc5e78f714976c6e42ae233c1990b0
Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit b6effaf4669b2c3707932e3c5f2f57df886d759e)

Gbp-Pq: Topic from-2.2.17
Gbp-Pq: Name gpg-Fix-regression-in-option-self-sigs-only.patch

g10/import.c

index 91222d292c322ac308f18aa0799fee6260bfc4ce..d509c8cfadacc109f0cfc1f0773be1f64f8d8b35 100644 (file)
@@ -855,6 +855,7 @@ read_block( IOBUF a, unsigned int options,
   kbnode_t root = NULL;
   int in_cert, in_v3key, skip_sigs;
   u32 keyid[2];
+  int got_keyid = 0;
   unsigned int dropped_nonselfsigs = 0;
 
   *r_v3keys = 0;
@@ -863,7 +864,11 @@ read_block( IOBUF a, unsigned int options,
     {
       root = new_kbnode( *pending_pkt );
       *pending_pkt = NULL;
+      log_assert (root->pkt->pkttype == PKT_PUBLIC_KEY
+                  || root->pkt->pkttype == PKT_SECRET_KEY);
       in_cert = 1;
+      keyid_from_pk (root->pkt->pkt.public_key, keyid);
+      got_keyid = 1;
     }
   else
     in_cert = 0;
@@ -985,6 +990,7 @@ read_block( IOBUF a, unsigned int options,
             goto x_default;
           if (!(options & IMPORT_SELF_SIGS_ONLY))
             goto x_default;
+          log_assert (got_keyid);
          if (pkt->pkt.signature->keyid[0] == keyid[0]
               && pkt->pkt.signature->keyid[1] == keyid[1])
            { /* This is likely a self-signature.  We import this one.
@@ -1007,6 +1013,11 @@ read_block( IOBUF a, unsigned int options,
 
         case PKT_PUBLIC_KEY:
         case PKT_SECRET_KEY:
+          if (!got_keyid)
+            {
+              keyid_from_pk (pkt->pkt.public_key, keyid);
+              got_keyid = 1;
+            }
           if (in_cert) /* Store this packet.  */
             {
               *pending_pkt = pkt;
@@ -1014,7 +1025,6 @@ read_block( IOBUF a, unsigned int options,
               goto ready;
             }
           in_cert = 1;
-          keyid_from_pk (pkt->pkt.public_key, keyid);
           goto x_default;
 
         default: