Don't add a key to the stats hash if it doesn't have any sigs
authorJonathan McDowell <noodles@earth.li>
Sat, 26 Dec 2009 12:09:21 +0000 (12:09 +0000)
committerJonathan McDowell <noodles@earth.li>
Sat, 26 Dec 2009 12:09:21 +0000 (12:09 +0000)
  We always added a key to the stats hash if we tried to find its sigs,
  even if it didn't exist. So if it doesn't have any sigs (either because
  it doesn't exist or it's just a non linked in key), don't add it.
  Closes Debian bug #542187.

keydb.c

diff --git a/keydb.c b/keydb.c
index 0039057093898bc067f5c3149ae9a0ec352559a9..42eebfe3a34c8b1e0ee4bc0c6b1c9ed9bafa0914 100644 (file)
--- a/keydb.c
+++ b/keydb.c
@@ -105,16 +105,24 @@ struct ll *generic_cached_getkeysigs(uint64_t keyid)
        struct stats_key *key = NULL;
        struct stats_key *signedkey = NULL;
        struct ll        *cursig = NULL;
+       struct ll        *sigs = NULL;
        bool              revoked = false;
 
        if (keyid == 0)  {
                return NULL;
        }
 
-       key = createandaddtohash(keyid);
+       key = findinhash(keyid);
 
-       if (key->gotsigs == false) {
-               key->sigs = config.dbbackend->getkeysigs(key->keyid, &revoked);
+       if (key == NULL || key->gotsigs == false) {
+               sigs = config.dbbackend->getkeysigs(keyid, &revoked);
+               if (sigs == NULL) {
+                       return NULL;
+               }
+               if (key == NULL) {
+                       key = createandaddtohash(keyid);
+               }
+               key->sigs = sigs;
                key->revoked = revoked;
                for (cursig = key->sigs; cursig != NULL;
                                cursig = cursig->next) {