From 6e51db8c80f538f1cb6a88dfd6ffc93122f11912 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Fri, 7 Sep 2018 12:54:32 +0200 Subject: [PATCH] lib: make the reader comparison case-insensitive sadly strcasestr is a GNU/BSD extension, not part of posix so we have to do our own thing here or do different things on different platforms. --- lib/ykpiv.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ykpiv.c b/lib/ykpiv.c index 5006b89..48b6d84 100644 --- a/lib/ykpiv.c +++ b/lib/ykpiv.c @@ -349,7 +349,19 @@ ykpiv_rc ykpiv_connect(ykpiv_state *state, const char *wanted) { for(reader_ptr = reader_buf; *reader_ptr != '\0'; reader_ptr += strlen(reader_ptr) + 1) { if(wanted) { - if(!strstr(reader_ptr, wanted)) { + char *ptr = reader_ptr; + bool found = false; + do { + if(strlen(ptr) < strlen(wanted)) { + break; + } + if(strncasecmp(ptr, wanted, strlen(wanted)) == 0) { + found = true; + break; + } + } while(*ptr++); + + if(found == false) { if(state->verbose) { fprintf(stderr, "skipping reader '%s' since it doesn't match '%s'.\n", reader_ptr, wanted); }