mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
agent: Fix passphrase cache lookups.
CACHE_MODE_ANY is supposed to match any cache mode except CACHE_MODE_IGNORE, but the code used '==' to compare cache modes. * agent/cache.c (cache_mode_equal): New function. (agent_set_cache): Use the new function to compare cache modes. (agent_get_cache): Likewise. * tests/openpgp/Makefile.am (TESTS): Add new test. * tests/openpgp/issue2015.scm: New file. GnuPG-bug-id: 2015 Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
7f4dd24b88
commit
f474249366
3 changed files with 41 additions and 2 deletions
|
@ -299,6 +299,15 @@ agent_flush_cache (void)
|
|||
}
|
||||
|
||||
|
||||
/* Compare two cache modes. */
|
||||
static int
|
||||
cache_mode_equal (cache_mode_t a, cache_mode_t b)
|
||||
{
|
||||
/* CACHE_MODE_ANY matches any mode other than CACHE_MODE_IGNORE. */
|
||||
return ((a == CACHE_MODE_ANY && b != CACHE_MODE_IGNORE)
|
||||
|| (b == CACHE_MODE_ANY && a != CACHE_MODE_IGNORE) || a == b);
|
||||
}
|
||||
|
||||
|
||||
/* Store the string DATA in the cache under KEY and mark it with a
|
||||
maximum lifetime of TTL seconds. If there is already data under
|
||||
|
@ -333,7 +342,7 @@ agent_put_cache (const char *key, cache_mode_t cache_mode,
|
|||
{
|
||||
if (((cache_mode != CACHE_MODE_USER
|
||||
&& cache_mode != CACHE_MODE_NONCE)
|
||||
|| r->cache_mode == cache_mode)
|
||||
|| cache_mode_equal (r->cache_mode, cache_mode))
|
||||
&& !strcmp (r->key, key))
|
||||
break;
|
||||
}
|
||||
|
@ -416,7 +425,7 @@ agent_get_cache (const char *key, cache_mode_t cache_mode)
|
|||
if (r->pw
|
||||
&& ((cache_mode != CACHE_MODE_USER
|
||||
&& cache_mode != CACHE_MODE_NONCE)
|
||||
|| r->cache_mode == cache_mode)
|
||||
|| cache_mode_equal (r->cache_mode, cache_mode))
|
||||
&& !strcmp (r->key, key))
|
||||
{
|
||||
/* Note: To avoid races KEY may not be accessed anymore below. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue