From b47838975388294154c7248b9a6592b76654c7c1 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 17 Jul 2009 11:24:51 +0000 Subject: [PATCH] Repalce an assert by a proper error message. --- g10/ChangeLog | 5 +++++ g10/keyring.c | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 1691b5800..68cf2d9ba 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2009-07-17 Werner Koch + + * 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 * misc.c (has_invalid_email_chars): Let non-ascii characters pass diff --git a/g10/keyring.c b/g10/keyring.c index ee6509678..4dc662ed9 100644 --- a/g10/keyring.c +++ b/g10/keyring.c @@ -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)