diff --git a/client/src/crypto/asn1dump.c b/client/src/crypto/asn1dump.c index 025e200ca..32dc8f051 100644 --- a/client/src/crypto/asn1dump.c +++ b/client/src/crypto/asn1dump.c @@ -15,7 +15,7 @@ //----------------------------------------------------------------------------- // asn.1 dumping //----------------------------------------------------------------------------- -#define _POSIX_C_SOURCE 200809L // need for strnlen() + #include "asn1dump.h" #include "commonutil.h" // ARRAYLEN @@ -344,17 +344,17 @@ static void asn1_tag_dump_object_id(const struct tlv *tlv, const struct asn1_tag } else { const char *ppstr = NULL; mbedtls_oid_get_attr_short_name(&asn1_buf, &ppstr); - if (ppstr && strnlen(ppstr, 1)) { + if (ppstr && str_nlen(ppstr, 1)) { PrintAndLogEx(NORMAL, " (%s)", ppstr); return; } mbedtls_oid_get_sig_alg_desc(&asn1_buf, &ppstr); - if (ppstr && strnlen(ppstr, 1)) { + if (ppstr && str_nlen(ppstr, 1)) { PrintAndLogEx(NORMAL, " (%s)", ppstr); return; } mbedtls_oid_get_extended_key_usage(&asn1_buf, &ppstr); - if (ppstr && strnlen(ppstr, 1)) { + if (ppstr && str_nlen(ppstr, 1)) { PrintAndLogEx(NORMAL, " (%s)", ppstr); return; } diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index 9c3326f83..077414c86 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -43,6 +43,7 @@ #include "mifare/mad.h" #include "mifare/aiddesfire.h" + const CLIParserOption DesfireAlgoOpts[] = { {T_DES, "des"}, {T_3DES, "2tdea"}, @@ -1749,7 +1750,7 @@ int DesfireFillAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS ap memcpy( appList[indx].appDFName, &buf[i * 24 + 1 + 5], - // strnlen((char *)&buf[i * 24 + 1 + 5], 16) + // str_nlen((char *)&buf[i * 24 + 1 + 5], 16) 16 ); } @@ -2879,7 +2880,7 @@ int DesfireISOSelect(DesfireContext_t *dctx, DesfireISOSelectControl cntr, uint8 } int DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, uint8_t *resp, size_t *resplen) { - return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, strnlen(dfname, 16), resp, resplen); + return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, str_nlen(dfname, 16), resp, resplen); } int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorithm keytype, uint8_t *resp, size_t *resplen) { diff --git a/client/src/util.c b/client/src/util.c index 640178959..79d3c312b 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -1198,6 +1198,16 @@ char *str_ndup(const char *src, size_t len) { return dest; } +size_t str_nlen(const char *src, size_t maxlen) { + size_t len = 0; + if(src { + for(char c = *src; (len < maxlen && c != '\0'); c = *++src) { + len++; + } + } + return len; +} + /** * Converts a hex string to component "hi2", "hi" and "lo" 32-bit integers * one nibble at a time. diff --git a/client/src/util.h b/client/src/util.h index 3b9a70183..1d6df987d 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -147,6 +147,7 @@ void strcleanrn(char *buf, size_t len); void strcreplace(char *buf, size_t len, char from, char to); char *str_dup(const char *src); char *str_ndup(const char *src, size_t len); +size_t str_nlen(const char *src, size_t maxlen); int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str); int binstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str); int binarray_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const uint8_t *arr, int arrlen);