1 From: NIIBE Yutaka <gniibe@fsij.org>
2 Date: Sun, 5 Feb 2017 08:34:08 +0900
3 Subject: scd: Backport two fixes from master.
5 * scd/app.c (app_new_register): Initialize by -1, so that it can detect
6 an error correctly when card reader can't power-on the card initially.
7 * scd/command.c (open_card_with_request): Release APP before the scan.
10 The first one-liner patch handles an erroneous card.
12 The second patch handles the case when we repeatedly do
13 signing/decrypting by a single session of scdaemon.
15 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
18 scd/command.c | 5 +++++
19 2 files changed, 6 insertions(+)
21 diff --git a/scd/app.c b/scd/app.c
22 index b10a452d6..989e0c060 100644
25 @@ -192,6 +192,7 @@ app_new_register (int slot, ctrl_t ctrl, const char *name)
29 + app->card_status = (unsigned int)-1;
31 if (npth_mutex_init (&app->lock, NULL))
33 diff --git a/scd/command.c b/scd/command.c
34 index 8c7ca20a6..0ae6d29aa 100644
37 @@ -217,6 +217,7 @@ open_card_with_request (ctrl_t ctrl, const char *apptype, const char *serialno)
39 unsigned char *serialno_bin = NULL;
40 size_t serialno_bin_len = 0;
41 + app_t app = ctrl->app_ctx;
43 /* If we are already initialized for one specific application we
44 need to check that the client didn't requested a specific
45 @@ -224,6 +225,10 @@ open_card_with_request (ctrl_t ctrl, const char *apptype, const char *serialno)
46 if (apptype && ctrl->app_ctx)
47 return check_application_conflict (apptype, ctrl->app_ctx);
49 + /* Re-scan USB devices. Release APP, before the scan. */
50 + ctrl->app_ctx = NULL;
51 + release_application (app);
54 serialno_bin = hex_to_buffer (serialno, &serialno_bin_len);