diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index 6332130ad..2aad98038 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -82,6 +82,10 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) { size_t nonce_length = resp.oldarg[1]; size_t nonce_length_bytes = 2 * nonce_length + 1; char *nonce = (char *) calloc(2 * nonce_length + 1, sizeof(uint8_t)); + if (nonce == NULL) { + PrintAndLogEx(FAILED, "Memory allocation failed for nonce"); + return PM3_EMALLOC; + } for (int j = 0; j < nonce_length; j++) { int nonce_offset = 2 * j; snprintf(nonce + nonce_offset, (nonce_length_bytes * sizeof(uint8_t)) - nonce_offset, "%02X", resp.data.asBytes[j]); diff --git a/client/src/cmdhfvas.c b/client/src/cmdhfvas.c index 195a4ef76..494868d0f 100644 --- a/client/src/cmdhfvas.c +++ b/client/src/cmdhfvas.c @@ -114,6 +114,10 @@ static int CreateGetVASDataCommand(const uint8_t *pidHash, const char *url, size size_t reqTlvLen = 19 + (pidHash != NULL ? 35 : 0) + (url != NULL ? 3 + urlLen : 0); uint8_t *reqTlv = calloc(reqTlvLen, sizeof(uint8_t)); + if (reqTlv == NULL) { + PrintAndLogEx(FAILED, "Memory allocation failed"); + return PM3_EMALLOC; + } uint8_t version[] = {0x9F, 0x22, 0x02, 0x01, 0x00}; memcpy(reqTlv, version, sizeof(version)); diff --git a/client/src/cmdlfguard.c b/client/src/cmdlfguard.c index bc498f9a4..d6979633a 100644 --- a/client/src/cmdlfguard.c +++ b/client/src/cmdlfguard.c @@ -291,6 +291,10 @@ static int CmdGuardClone(const char *Cmd) { //GuardProxII - compat mode, ASK/Biphase, data rate 64, 3 data blocks uint8_t *bs = calloc(96, sizeof(uint8_t)); + if (bs == NULL) { + PrintAndLogEx(ERR, "Memory allocation failed."); + return PM3_EMALLOC; + } if (getGuardBits(xorval, fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); free(bs); diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index 9360e6d3e..713364efb 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -199,6 +199,10 @@ static int CmdNoralsyClone(const char *Cmd) { } uint8_t *bits = calloc(96, sizeof(uint8_t)); + if (bits == NULL) { + PrintAndLogEx(ERR, "Memory allocation failed."); + return PM3_EMALLOC; + } if (getnoralsyBits(id, year, bits) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); free(bits); diff --git a/client/src/emv/test/cda_test.c b/client/src/emv/test/cda_test.c index eb4a031f4..22c865785 100644 --- a/client/src/emv/test/cda_test.c +++ b/client/src/emv/test/cda_test.c @@ -182,6 +182,10 @@ static int cda_test_raw(bool verbose) { size_t ipk_pk_len = ipk_data[13]; unsigned char *ipk_pk = calloc(1, ipk_pk_len); + if (!ipk_pk) { + free(ipk_data); + return 1; + } memcpy(ipk_pk, ipk_data + 15, ipk_data_len - 36); memcpy(ipk_pk + ipk_data_len - 36, c_issuer_rem, sizeof(c_issuer_rem)); diff --git a/client/src/emv/test/dda_test.c b/client/src/emv/test/dda_test.c index fe7991849..1adcdfec0 100644 --- a/client/src/emv/test/dda_test.c +++ b/client/src/emv/test/dda_test.c @@ -170,6 +170,10 @@ static int dda_test_raw(bool verbose) { size_t ipk_pk_len = ipk_data[13]; unsigned char *ipk_pk = calloc(1, ipk_pk_len); + if (!ipk_pk) { + free(ipk_data); + return 1; + } memcpy(ipk_pk, ipk_data + 15, ipk_data_len - 36); memcpy(ipk_pk + ipk_data_len - 36, d_issuer_rem, sizeof(d_issuer_rem)); diff --git a/client/src/emv/test/sda_test.c b/client/src/emv/test/sda_test.c index f8abad8da..b16a1e0b7 100644 --- a/client/src/emv/test/sda_test.c +++ b/client/src/emv/test/sda_test.c @@ -132,6 +132,10 @@ static int sda_test_raw(bool verbose) { size_t ipk_pk_len = ipk_data[13]; unsigned char *ipk_pk = calloc(1, ipk_pk_len); + if (!ipk_pk) { + free(ipk_data); + return 1; + } memcpy(ipk_pk, ipk_data + 15, ipk_data_len - 36); memcpy(ipk_pk + ipk_data_len - 36, issuer_rem, sizeof(issuer_rem)); diff --git a/client/src/ui.c b/client/src/ui.c index 228e782a2..d8c532ff4 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -715,6 +715,10 @@ void print_progress(uint64_t count, uint64_t max, barMode_t style) { size_t unit = strlen(block[mode]); // +1 for \0 char *bar = (char *)calloc(unit * width + 1, sizeof(uint8_t)); + if (bar == NULL) { + fprintf(stderr, "Memory allocation failed for progress bar\n"); + return; + } uint8_t value = PERCENTAGE(count, max); @@ -739,6 +743,11 @@ void print_progress(uint64_t count, uint64_t max, barMode_t style) { // color buffer size_t collen = strlen(bar) + 40; char *cbar = (char *)calloc(collen, sizeof(uint8_t)); + if (cbar == NULL) { + fprintf(stderr, "Memory allocation failed for color buffer\n"); + free(bar); + return; + } // Add colors if (g_session.supports_colors) {