From 92be4e87eec984a3f3737339c311761d2650c55a Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 11 Sep 2019 11:05:03 +0900 Subject: [PATCH] scd,pcsc: Fix examining the list of readers. * scd/apdu.c (apdu_dev_list_start): Traverse the string+NUL carefully. Signed-off-by: NIIBE Yutaka --- scd/apdu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scd/apdu.c b/scd/apdu.c index 958b47e1a..af747c07d 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -1998,17 +1998,25 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p) while (nreader) { - if (!*p && !p[1]) + size_t n; + + if (!*p) break; - log_info ("detected reader '%s'\n", p); - if (nreader < (strlen (p)+1)) + + for (n = 0; n < nreader; n++) + if (!p[n]) + break; + + if (n >= nreader) { log_error ("invalid response from pcsc_list_readers\n"); break; } + + log_info ("detected reader '%s'\n", p); pcsc.rdrname[dl->idx_max] = p; - nreader -= strlen (p)+1; - p += strlen (p) + 1; + nreader -= n + 1; + p += n + 1; dl->idx_max++; if (dl->idx_max >= MAX_READER) {