diff options
author | Werner Koch <[email protected]> | 2020-11-26 11:16:56 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-11-26 11:16:56 +0000 |
commit | d784e763495c8d53e29a2debdd9c0e0578f15a6a (patch) | |
tree | 0cb5367ca173205424a60f6b81a32350fe12c2c0 /scd/app.c | |
parent | scd: Add special serialno compare for OpenPGP cards. (diff) | |
download | gnupg-d784e763495c8d53e29a2debdd9c0e0578f15a6a.tar.gz gnupg-d784e763495c8d53e29a2debdd9c0e0578f15a6a.zip |
scd: Do not try to use a non-enabled app after card switching.
* scd/app.c (app_dump_state): Also print the refcount.
(maybe_switch_app): Make sure the app exists on the card.
--
When switching the current card and the card does not support the same
apps as the former, we now reset the app to the first one.
Testcase is to use a standard OpenPGP card and a P15 card.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'scd/app.c')
-rw-r--r-- | scd/app.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -304,8 +304,8 @@ app_dump_state (void) npth_mutex_lock (&card_list_lock); for (c = card_top; c; c = c->next) { - log_info ("app_dump_state: card=%p slot=%d type=%s\n", - c, c->slot, strcardtype (c->cardtype)); + log_info ("app_dump_state: card=%p slot=%d type=%s refcount=%u\n", + c, c->slot, strcardtype (c->cardtype), c->ref_count); /* FIXME The use of log_info risks a race! */ for (a=c->app; a; a = a->next) log_info ("app_dump_state: app=%p type='%s'\n", @@ -1435,6 +1435,23 @@ maybe_switch_app (ctrl_t ctrl, card_t card, const char *keyref) { /* For whatever reasons the current apptype has not been set - * fix that and use the current app. */ + if (DBG_APP) + log_debug ("slot %d: no current app switching to %s\n", + card->slot, strapptype (card->app->apptype)); + ctrl->current_apptype = card->app->apptype; + return 0; + } + for (app = card->app; app; app = app->next) + if (app->apptype == ctrl->current_apptype) + break; + if (!app) + { + /* The current app is not supported by this card. Set the first + * app of the card as current. */ + if (DBG_APP) + log_debug ("slot %d: current app %s not available switching to %s\n", + card->slot, strapptype (ctrl->current_apptype), + strapptype (card->app->apptype)); ctrl->current_apptype = card->app->apptype; return 0; } |