aboutsummaryrefslogtreecommitdiffstats
path: root/g10/keydb.c
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2015-08-31 07:47:58 +0000
committerNeal H. Walfield <[email protected]>2015-08-31 09:30:55 +0000
commitefd1ead9e779eb3bd37384258e08ad921a934612 (patch)
tree90c455b3f9c80e5d0a0aca8dc59a2d7299641b68 /g10/keydb.c
parentg10: Have keydb_search_first call keydb_search_reset before searching. (diff)
downloadgnupg-efd1ead9e779eb3bd37384258e08ad921a934612.tar.gz
gnupg-efd1ead9e779eb3bd37384258e08ad921a934612.zip
g10: Don't cache search results if the search didn't scan the whole DB.
* g10/keydb.c (struct keydb_handle): Add new field is_reset. (keydb_new): Initialize hd->is_reset to 1. (keydb_locate_writable): Set hd->is_reset to 1. (keydb_search): Set hd->is_reset to 0. Don't cache a key not found if the search started from the beginning of the database. -- Signed-off-by: Neal H. Walfield <[email protected]>.
Diffstat (limited to 'g10/keydb.c')
-rw-r--r--g10/keydb.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/g10/keydb.c b/g10/keydb.c
index ea3280f26..eeefd2aa8 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -69,6 +69,11 @@ struct keydb_handle
int saved_found;
unsigned long skipped_long_blobs;
int no_caching;
+
+ /* Whether the next search will be from the beginning of the
+ database (and thus consider all records). */
+ int is_reset;
+
int current;
int used; /* Number of items in ACTIVE. */
struct resource_item active[MAX_KEYDB_RESOURCES];
@@ -676,6 +681,7 @@ keydb_new (void)
hd = xmalloc_clear (sizeof *hd);
hd->found = -1;
hd->saved_found = -1;
+ hd->is_reset = 1;
assert (used_resources <= MAX_KEYDB_RESOURCES);
for (i=j=0; i < used_resources; i++)
@@ -1568,6 +1574,7 @@ keydb_search_reset (KEYDB_HANDLE hd)
break;
}
}
+ hd->is_reset = 1;
return rc;
}
@@ -1630,6 +1637,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
size_t ndesc, size_t *descindex)
{
gpg_error_t rc;
+ int was_reset = hd->is_reset;
int already_in_cache = 0;
if (descindex)
@@ -1696,6 +1704,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
else if (!rc)
hd->found = hd->current;
}
+ hd->is_reset = 0;
rc = ((rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF)
? gpg_error (GPG_ERR_NOT_FOUND)
@@ -1712,7 +1721,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
}
if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND
- && ndesc == 1 && desc[0].mode == KEYDB_SEARCH_MODE_LONG_KID
+ && ndesc == 1 && desc[0].mode == KEYDB_SEARCH_MODE_LONG_KID && was_reset
&& !already_in_cache)
kid_not_found_insert (desc[0].u.kid);