gpg: Fix keyring retrieval.
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 10 Jul 2019 06:06:54 +0000 (15:06 +0900)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
* g10/keyring.c (keyring_get_keyblock): Avoid O(N^2) append.

--

Cherry-picking the master commit of:
a7a043e82555a9da984c6fb01bfec4990d904690

GnuPG-bug-id: 4592
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
(cherry picked from commit b7df72d3074b72cf8b537ac87416b6b719c1b1b7)

Gbp-Pq: Topic from-2.2.18-prerelease
Gbp-Pq: Name gpg-Fix-keyring-retrieval.patch

g10/keyring.c

index a8dd462652e26c7ca7f082809ceba6ec602abd81..f424f94fc3533067ce4a35893b12cea325a76a2a 100644 (file)
@@ -473,11 +473,14 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
         }
 
         in_cert = 1;
-        node = lastnode = new_kbnode (pkt);
+        node = new_kbnode (pkt);
         if (!keyblock)
-          keyblock = node;
+          keyblock = lastnode = node;
         else
-          add_kbnode (keyblock, node);
+          {
+            lastnode->next = node;
+            lastnode = node;
+          }
         switch (pkt->pkttype)
           {
           case PKT_PUBLIC_KEY: