gpg: Also delete key-binding signature when deleting a subkey.
authorWerner Koch <wk@gnupg.org>
Tue, 15 Oct 2019 12:30:57 +0000 (14:30 +0200)
committerWerner Koch <wk@gnupg.org>
Tue, 15 Oct 2019 12:30:57 +0000 (14:30 +0200)
* g10/delkey.c (do_delete_key): Simplify and correct subkey deletion.
--

GnuPG-bug-id: 4665, 4457
Fixes-commit: cc6069ac6ecd57dcbb808f28d54fd9f89dc55014
Signed-off-by: Werner Koch <wk@gnupg.org>
g10/delkey.c

index 8a7144a..41bd705 100644 (file)
@@ -279,21 +279,14 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force,
 
           /* Delete the specified public subkey.  */
           for (kbctx=NULL; (node = walk_kbnode (keyblock, &kbctx, 0)); )
-            {
-              if (thiskeyonly && targetnode != node)
-                continue;
+            if (targetnode == node)
+              break;
+          log_assert (node);
+          delete_kbnode (node);
+          while ((node = walk_kbnode (keyblock, &kbctx, 0))
+                 && node->pkt->pkttype == PKT_SIGNATURE)
+            delete_kbnode (node);
 
-              if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
-                {
-                  selected = targetnode == node;
-                  if (selected)
-                    delete_kbnode (node);
-                }
-              else if (selected && node->pkt->pkttype == PKT_SIGNATURE)
-                delete_kbnode (node);
-              else
-                selected = 0;
-            }
           commit_kbnode (&keyblock);
           err = keydb_update_keyblock (ctrl, hd, keyblock);
           if (err)