From 1ab9d24b5c6c3a8ae85fc3ca29f7e84943a013fd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 10 Oct 2021 14:26:00 +0200 Subject: [PATCH] calloc and check. remove add char. --- client/atr_scrap_eftlab.py | 2 +- client/src/atrs.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/atr_scrap_eftlab.py b/client/atr_scrap_eftlab.py index 9b780fd7b..ea438b70b 100755 --- a/client/atr_scrap_eftlab.py +++ b/client/atr_scrap_eftlab.py @@ -20,7 +20,7 @@ def print_atr(df): if (len(a) == 0 or len(b) == 0): continue - b = b.replace('\\', '\\\\') + b = b.replace('\\', '\\\\').replace('’', '') print(f' {{ "{a}", "{b}" }},') diff --git a/client/src/atrs.c b/client/src/atrs.c index 7b2c6c318..e282b5e8d 100644 --- a/client/src/atrs.c +++ b/client/src/atrs.c @@ -20,22 +20,27 @@ const char *getAtrInfo(const char *atr_str) { int match = -1; // skip last element of AtrTable for (int i = 0; i < ARRAYLEN(AtrTable) - 1; ++i) { + if (strlen(AtrTable[i].bytes) != slen) continue; + if (strstr(AtrTable[i].bytes, "..") != NULL) { - char *tmp_atr = malloc(slen); - if (!tmp_atr) { - PrintAndLogEx(ERR, "Out of memory error in getAtrInfo(). Aborting..."); + char *tmp_atr = calloc(slen, sizeof(uint8_t)); + if (tmp_atr == NULL) { + PrintAndLogEx(FAILED, "failed to allocate memory"); return NULL; } + for (int j = 0; j < slen; j++) { tmp_atr[j] = AtrTable[i].bytes[j]=='.' ? '.' : atr_str[j]; } + if (strncmp(tmp_atr, AtrTable[i].bytes, slen) == 0) { // record partial match but continue looking for full match match = i; } free(tmp_atr); + } else { if (strncmp(atr_str, AtrTable[i].bytes, slen) == 0) return AtrTable[i].desc; }