Repalce an assert by a proper error message.
authorWerner Koch <wk@gnupg.org>
Fri, 17 Jul 2009 11:24:51 +0000 (11:24 +0000)
committerWerner Koch <wk@gnupg.org>
Fri, 17 Jul 2009 11:24:51 +0000 (11:24 +0000)
g10/ChangeLog
g10/keyring.c

index 1691b58..68cf2d9 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-17  Werner Koch  <wk@g10code.com>
+
+       * keyring.c (keyring_rebuild_cache): Replace the assert by a
+       proper error message and allow to delete a bad keyblock.
+
 2009-07-16  Werner Koch  <wk@g10code.com>
 
        * misc.c (has_invalid_email_chars): Let non-ascii characters pass
index ee65096..4dc662e 100644 (file)
@@ -1399,7 +1399,20 @@ keyring_rebuild_cache (void *token,int noisy)
           log_error ("keyring_get_keyblock failed: %s\n", g10_errstr(rc));
           goto leave;
         }
-      assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY);
+      if ( keyblock->pkt->pkttype != PKT_PUBLIC_KEY)
+        {
+          /* We had a few reports about corrupted keyrings; if we have
+             been called directly from the command line we delete such
+             a keyblock instead of bailing out.  */
+          log_error ("unexpected keyblock found (pkttype=%d)%s\n",
+                     keyblock->pkt->pkttype, noisy? " - deleted":"");
+          if (noisy)
+            continue;
+          log_info ("Hint: backup your keys and try running `%s'\n",
+                    "gpg --rebuild-keydb-caches");
+          rc = G10ERR_INV_KEYRING;
+          goto leave;
+        }
 
       /* check all signature to set the signature's cache flags */
       for (node=keyblock; node; node=node->next)