From 3802703ef22920758864c080b7a2ea3c64dd7ca8 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 13 May 2021 10:35:08 +0900 Subject: scd: Protect PCSC.CONTEXT in apdu_dev_list_start. * scd/apdu.c (apdu_dev_list_start): Make sure using valid PCSC.CONTEXT. -- Signed-off-by: NIIBE Yutaka --- scd/apdu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scd/apdu.c b/scd/apdu.c index ae6d8664b..a081b37f0 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -2018,12 +2018,14 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p) pcsc_dword_t nreader; char *p = NULL; + npth_mutex_lock (&reader_table_lock); if (!pcsc.context) { /* log_debug ("%s: No context - calling init\n", __func__); */ if (pcsc_init () < 0) { xfree (dl); + npth_mutex_unlock (&reader_table_lock); return gpg_error (GPG_ERR_NO_SERVICE); } } @@ -2040,6 +2042,7 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p) if (pcsc.count == 0) release_pcsc_context (); xfree (dl); + npth_mutex_unlock (&reader_table_lock); return err; } r = pcsc_list_readers (pcsc.context, NULL, p, &nreader); @@ -2052,9 +2055,12 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p) if (pcsc.count == 0) release_pcsc_context (); xfree (dl); + npth_mutex_unlock (&reader_table_lock); return iso7816_map_sw (pcsc_error_to_sw (r)); } + npth_mutex_unlock (&reader_table_lock); + dl->table = p; dl->idx_max = 0; -- cgit v1.2.3