From ee5b6af370fbee1b08136e5dc384cf7996bcfc4c Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 7 Jun 2021 11:38:25 +0900 Subject: [PATCH] scd: Fix READER-PORT option handling for PC/SC. * scd/apdu.c (apdu_open_reader): READERNO should be -1 when READER-PORT is specified for PC/SC. -- Signed-off-by: NIIBE Yutaka --- scd/apdu.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/scd/apdu.c b/scd/apdu.c index 62aefb8cf..ec495e374 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -2129,32 +2129,42 @@ apdu_open_reader (struct dev_list *dl) if (!dl->table) return -1; +#ifdef HAVE_LIBUSB /* See whether we want to use the reader ID string or a reader number. A readerno of -1 indicates that the reader ID string is to be used. */ - if (dl->portstr && strchr (dl->portstr, ':')) - readerno = -1; /* We want to use the readerid. */ - else if (dl->portstr) + if (dl->portstr) { - readerno = atoi (dl->portstr); - if (readerno < 0 || readerno >= dl->idx_max) - return -1; - - npth_mutex_lock (&reader_table_lock); - /* If already opened HANDLE, return -1. */ - for (slot = 0; slot < MAX_READER; slot++) - if (reader_table[slot].used) - { - npth_mutex_unlock (&reader_table_lock); + if (!opt.disable_ccid || strchr (dl->portstr, ':')) + readerno = -1; /* We want to use the readerid. */ + else + { + readerno = atoi (dl->portstr); + if (readerno < 0 || readerno >= dl->idx_max) return -1; - } - npth_mutex_unlock (&reader_table_lock); - dl->idx = readerno; - dl->portstr = NULL; + npth_mutex_lock (&reader_table_lock); + /* If already opened HANDLE, return -1. */ + for (slot = 0; slot < MAX_READER; slot++) + if (reader_table[slot].used) + { + npth_mutex_unlock (&reader_table_lock); + return -1; + } + npth_mutex_unlock (&reader_table_lock); + + dl->idx = readerno; + dl->portstr = NULL; + } } else readerno = 0; /* Default. */ +#else + if (dl->portstr) + readerno = -1; /* We want to use the readerid. */ + else + readerno = 0; /* Default. */ +#endif #ifdef HAVE_LIBUSB if (!opt.disable_ccid)