aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-11-26 12:16:56 +0100
committerWerner Koch <wk@gnupg.org>2020-11-26 12:16:56 +0100
commitd784e763495c8d53e29a2debdd9c0e0578f15a6a (patch)
tree0cb5367ca173205424a60f6b81a32350fe12c2c0
parent764c69a841abc1a4dff2fa86b4cd0b63ec737860 (diff)
downloadgnupg-d784e763495c8d53e29a2debdd9c0e0578f15a6a.tar.gz
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 <wk@gnupg.org>
-rw-r--r--scd/app.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/scd/app.c b/scd/app.c
index 7ba714b3e..933ad46d6 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -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;
}