use a local str_nlen fct instead of hinting to POSIX

This commit is contained in:
iceman1001 2023-11-05 02:08:30 +01:00
parent a3415da519
commit 2ccf84f40a
4 changed files with 18 additions and 6 deletions

View file

@ -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;
}

View file

@ -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) {

View file

@ -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.

View file

@ -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);