From c9eb4c0632318270dea7cc4c22957539648a3707 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 3 Dec 2020 16:21:49 +0900 Subject: [PATCH] scd:nks: Fix caching keygrip (more). * scd/app-nks.c (keygripstr_from_pk_file): Distinguish by APP_ID. -- GnuPG-bug-id: 5150, 5161 Signed-off-by: NIIBE Yutaka Backported-from-master: 87d2c579cc38c1d2787945650125fb0e0336652c Fixes-commit: 00f594e3ecb26b010e87d5491b648369e7a92408 --- scd/app-nks.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scd/app-nks.c b/scd/app-nks.c index 99f769f79..ec08eeb0f 100644 --- a/scd/app-nks.c +++ b/scd/app-nks.c @@ -176,6 +176,7 @@ static struct /* Object to cache information gathered from FIDs. */ struct fid_cache_s { struct fid_cache_s *next; + int nks_app_id; int fid; /* Zero for an unused slot. */ unsigned int got_keygrip:1; /* The keygrip and algo are valid. */ int algo; @@ -294,8 +295,8 @@ keygripstr_from_pk_file (app_t app, int pkfid, int cfid, char *r_gripstr, struct fid_cache_s *ci; for (ci = app->app_local->fid_cache; ci; ci = ci->next) - if (ci->fid && ((cfid > 0 && ci->fid == cfid) - || (!(cfid > 0) && ci->fid == pkfid))) + if (ci->fid && ci->nks_app_id == app->app_local->active_nks_app + && ci->fid == pkfid) { if (!ci->got_keygrip) return gpg_error (GPG_ERR_NOT_FOUND); @@ -465,8 +466,8 @@ keygripstr_from_pk_file (app_t app, int pkfid, int cfid, char *r_gripstr, /* FIXME: We need to implement not_found caching. */ for (ci = app->app_local->fid_cache; ci; ci = ci->next) if (ci->fid - && ((cfid > 0 && ci->fid == cfid) - || (!(cfid > 0) && ci->fid == pkfid))) + && ci->nks_app_id == app->app_local->active_nks_app + && ci->fid == pkfid) { /* Update the keygrip. */ memcpy (ci->keygripstr, r_gripstr, 2*KEYGRIP_LEN+1); @@ -487,7 +488,8 @@ keygripstr_from_pk_file (app_t app, int pkfid, int cfid, char *r_gripstr, ; /* Out of memory - it is a cache, so we ignore it. */ else { - ci->fid = (cfid > 0)? cfid : pkfid; + ci->nks_app_id = app->app_local->active_nks_app; + ci->fid = pkfid; memcpy (ci->keygripstr, r_gripstr, 2*KEYGRIP_LEN+1); ci->algo = algo; ci->got_keygrip = 1;