1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-20 14:37:08 +01:00

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 <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2021-05-13 10:35:08 +09:00
parent 310b064f52
commit 3802703ef2

View File

@ -2018,12 +2018,14 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p)
pcsc_dword_t nreader; pcsc_dword_t nreader;
char *p = NULL; char *p = NULL;
npth_mutex_lock (&reader_table_lock);
if (!pcsc.context) if (!pcsc.context)
{ {
/* log_debug ("%s: No context - calling init\n", __func__); */ /* log_debug ("%s: No context - calling init\n", __func__); */
if (pcsc_init () < 0) if (pcsc_init () < 0)
{ {
xfree (dl); xfree (dl);
npth_mutex_unlock (&reader_table_lock);
return gpg_error (GPG_ERR_NO_SERVICE); 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) if (pcsc.count == 0)
release_pcsc_context (); release_pcsc_context ();
xfree (dl); xfree (dl);
npth_mutex_unlock (&reader_table_lock);
return err; return err;
} }
r = pcsc_list_readers (pcsc.context, NULL, p, &nreader); 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) if (pcsc.count == 0)
release_pcsc_context (); release_pcsc_context ();
xfree (dl); xfree (dl);
npth_mutex_unlock (&reader_table_lock);
return iso7816_map_sw (pcsc_error_to_sw (r)); return iso7816_map_sw (pcsc_error_to_sw (r));
} }
npth_mutex_unlock (&reader_table_lock);
dl->table = p; dl->table = p;
dl->idx_max = 0; dl->idx_max = 0;