Home GnuPG
Diffusion GnuPG 7546e8187919

gpg: Fix cache consistency problem.
7546e8187919Unpublished

Unpublished Commit ยท Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.

Description

gpg: Fix cache consistency problem.

g10/keyring.c (keyring_search): Only mark the cache as completely
filled if we start the scan from the beginning of the keyring.

A new feature (e8c53fc) turned up a bug whereby checking if a search
term matches multiple keys in the keyring causes the cache to be
inconsistent.

When we look for a key on the keyring, we iterate over each of the
keyblocks starting with the keyblock following the last result. For
each keyblock, we iterate over the public key and any subkeys. As we
iterate over each key, we first insert it into the cache and then
check if the key matches. If so, we are done.

In pseudo code:

for (i = last_result + 1; i < num_records; i ++)
  keyblock = get_keyblock (i)
  for (j = 1; j < len(keyblock); j ++)
    key = keyblock[j]
    update_cache (key)
    if (compare (key, search_terms))
      return ok
cache_filled = true
return ENOFOUND

When we look for the next match, we start with the following keyblock.
The result is that any subkeys following the key that matched are not
added to the cache (in other words, when a keyblock matches, the inner
loop did not necessarily complete and the subsequent search doesn't
resume it).

This patch includes a straightforward fix: only indicate the cache as
complete if we started the scan from the beginning of the keyring and
really didn't find anything.

  • Signed-off-by: Neal H. Walfield <neal@g10code.com>
  • Reported-by: NIIBE Yutaka <gniibe@fsij.org>

Details

Provenance
Neal H. Walfield <neal@g10code.com>Authored on Nov 11 2015, 6:26 PM
Parents
rG67c701d1e53f: gpg: Default to the the PGP trust model.
Branches
Unknown
Tags
Unknown

Event Timeline

Neal H. Walfield <neal@g10code.com> committed rG7546e8187919: gpg: Fix cache consistency problem. (authored by Neal H. Walfield <neal@g10code.com>).Nov 11 2015, 6:32 PM
neal mentioned this in Unknown Object (Maniphest Task).Mar 27 2017, 5:08 PM
neal mentioned this in Unknown Object (Maniphest Task).Mar 27 2017, 5:31 PM