From ad292e8810be5128d2df048c33a91e3034ac00d2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 25 Mar 2025 10:17:42 +0100 Subject: [PATCH] unify test - step 2 --- client/src/cmdhfemrtd.c | 12 ++++++++- client/src/cmdhfepa.c | 4 ++- client/src/cmdhffelica.c | 4 +-- client/src/cmdhffudan.c | 5 ++-- client/src/cmdhfgallagher.c | 2 +- client/src/cmdhficlass.c | 21 ++++++++------- client/src/cmdhfict.c | 2 +- client/src/cmdhfjooki.c | 2 +- client/src/cmdhflegic.c | 34 ++++++++++++------------ client/src/cmdhflto.c | 4 +-- client/src/cmdhfmf.c | 37 ++++++++++++++------------- client/src/cmdhfmfdes.c | 10 +++++--- client/src/cmdhfmfhard.c | 10 ++++++++ client/src/cmdhfmfp.c | 4 +-- client/src/cmdhfmfu.c | 10 ++++---- client/src/cmdhfntag424.c | 14 ++++++---- client/src/cmdhftopaz.c | 5 ++-- client/src/cmdhfvas.c | 2 +- client/src/cmdhfxerox.c | 2 +- client/src/cmdhw.c | 4 +-- client/src/cmdlf.c | 6 ++--- client/src/cmdlfawid.c | 9 +++---- client/src/cmdlffdxb.c | 4 +-- client/src/cmdlfgallagher.c | 2 +- client/src/cmdlfguard.c | 4 +-- client/src/cmdlfhid.c | 2 +- client/src/cmdlfhitag.c | 14 +++++----- client/src/cmdlfindala.c | 6 ++--- client/src/cmdlfio.c | 4 +-- client/src/cmdlfkeri.c | 2 +- client/src/cmdlfnedap.c | 2 +- client/src/cmdlfnexwatch.c | 6 ++--- client/src/cmdlfnoralsy.c | 4 +-- client/src/cmdlfpac.c | 2 +- client/src/cmdlfparadox.c | 4 +-- client/src/cmdlfpresco.c | 2 +- client/src/cmdlfpyramid.c | 6 ++--- client/src/cmdlfsecurakey.c | 2 +- client/src/cmdlft55xx.c | 6 ++--- client/src/cmdlfviking.c | 2 +- client/src/cmdlfvisa2000.c | 2 +- client/src/cmdmain.c | 2 +- client/src/cmdpiv.c | 7 ++--- client/src/cmdsmartcard.c | 34 ++++++++++++------------ client/src/cmdtrace.c | 4 +-- client/src/cmdwiegand.c | 2 +- client/src/comms.c | 4 ++- client/src/crypto/asn1dump.c | 2 +- client/src/crypto/asn1utils.c | 2 ++ client/src/emv/crypto_polarssl.c | 8 ++++-- client/src/emv/emv_pk.c | 2 ++ client/src/emv/emv_pki.c | 2 +- client/src/emv/emv_tags.c | 2 +- client/src/flash.c | 4 +-- client/src/graph.c | 23 +++++++++-------- client/src/iso7816/apduinfo.c | 11 +++++--- client/src/loclass/cipher.c | 2 +- client/src/loclass/cipherutils.c | 2 +- client/src/loclass/elite_crack.c | 4 +-- client/src/loclass/ikeys.c | 4 +-- client/src/mifare/desfirecore.c | 6 +++++ client/src/mifare/desfiresecurechan.c | 23 ++++++++++++----- client/src/mifare/mifarehost.c | 5 +++- client/src/nfc/ndef.c | 2 +- client/src/preferences.c | 4 +-- client/src/proxmark3.c | 6 ++--- client/src/uart/uart_posix.c | 2 +- client/src/uart/uart_win32.c | 9 ++++--- client/src/ui.c | 9 ++++--- client/src/wiegand_formats.c | 1 + 70 files changed, 272 insertions(+), 195 deletions(-) diff --git a/client/src/cmdhfemrtd.c b/client/src/cmdhfemrtd.c index b21435a35..896877a74 100644 --- a/client/src/cmdhfemrtd.c +++ b/client/src/cmdhfemrtd.c @@ -802,8 +802,10 @@ static int emrtd_dump_ef_dg2(uint8_t *file_contents, size_t file_length, const c } char *filepath = calloc(strlen(path) + 100, sizeof(char)); - if (filepath == NULL) + if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; + } strcpy(filepath, path); strncat(filepath, PATHSEP, 2); @@ -827,6 +829,7 @@ static int emrtd_dump_ef_dg5(uint8_t *file_contents, size_t file_length, const c if (datalen < EMRTD_MAX_FILE_SIZE) { char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } strcpy(filepath, path); @@ -855,6 +858,7 @@ static int emrtd_dump_ef_dg7(uint8_t *file_contents, size_t file_length, const c if (datalen < EMRTD_MAX_FILE_SIZE) { char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } strcpy(filepath, path); @@ -882,6 +886,7 @@ static int emrtd_dump_ef_sod(uint8_t *file_contents, size_t file_length, const c char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -904,6 +909,7 @@ static bool emrtd_dump_file(uint8_t *ks_enc, uint8_t *ks_mac, uint8_t *ssc, uint char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return false; } @@ -1124,6 +1130,7 @@ int dumpHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_availab char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -2095,6 +2102,7 @@ int infoHF_EMRTD_offline(const char *path) { size_t datalen = 0; char *filepath = calloc(strlen(path) + 100, sizeof(char)); if (filepath == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } strcpy(filepath, path); @@ -2168,11 +2176,13 @@ int infoHF_EMRTD_offline(const char *path) { // Read files in the file list for (int i = 0; i < filelistlen; i++) { + emrtd_dg_t *dg = emrtd_tag_to_dg(filelist[i]); if (dg == NULL) { PrintAndLogEx(INFO, "File tag not found, skipping... %02X", filelist[i]); continue; } + if (!dg->pace && !dg->eac) { strcpy(filepath, path); strncat(filepath, PATHSEP, 2); diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index 2aad98038..c59d2b51a 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -81,11 +81,13 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) { } else { 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"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); 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/cmdhffelica.c b/client/src/cmdhffelica.c index 4336ed100..d52cb52da 100644 --- a/client/src/cmdhffelica.c +++ b/client/src/cmdhffelica.c @@ -2089,11 +2089,11 @@ static int CmdHFFelicaDumpLite(const char *Cmd) { uint8_t *trace = calloc(tracelen, sizeof(uint8_t)); if (trace == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory "); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } - if (!GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false)) { + if (GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false) == false) { PrintAndLogEx(WARNING, "command execution time out"); free(trace); return PM3_ETIMEOUT; diff --git a/client/src/cmdhffudan.c b/client/src/cmdhffudan.c index 23b364bf7..52ed3bc5f 100644 --- a/client/src/cmdhffudan.c +++ b/client/src/cmdhffudan.c @@ -72,7 +72,7 @@ static char *GenerateFilename(iso14a_card_select_t *card, const char *prefix, co } char *fptr = calloc(sizeof(char) * (strlen(prefix) + strlen(suffix)) + sizeof(card->uid) * 2 + 1, sizeof(uint8_t)); if (fptr == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } strcpy(fptr, prefix); @@ -344,8 +344,9 @@ static int CmdHFFudanDump(const char *Cmd) { // create filename if none was given if (strlen(dataFilename) < 1) { char *fptr = GenerateFilename(&card, "hf-fudan-", "-dump"); - if (fptr == NULL) + if (fptr == NULL) { return PM3_ESOFT; + } strcpy(dataFilename, fptr); free(fptr); diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index ec66bb5e6..5b018387c 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -60,7 +60,7 @@ int hfgal_diversify_key(uint8_t *site_key, uint8_t *uid, uint8_t uid_len, int res = mfdes_kdf_input_gallagher(uid, uid_len, key_num, aid, key_output, &kdf_input_len); PM3_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input"); - uint8_t key[sizeof(DEFAULT_SITE_KEY)]; + uint8_t key[sizeof(DEFAULT_SITE_KEY)] = {0}; if (site_key == NULL) { PrintAndLogEx(INFO, "hfgal_diversify_key is using default site key"); memcpy(key, DEFAULT_SITE_KEY, sizeof(key)); diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index a49911ee7..b21282ce2 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -387,7 +387,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke // normal size uint8_t *data = calloc(1, tot_bytes); if (data == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -433,7 +433,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke uint8_t *p = realloc(data, tot_bytes); if (p == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(data); return PM3_EMALLOC; } @@ -935,7 +935,7 @@ static int CmdHFiClassSim(const char *Cmd) { size_t datalen = NUM_CSNS * MAC_ITEM_SIZE; uint8_t *dump = calloc(datalen, sizeof(uint8_t)); - if (!dump) { + if (dump == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -986,7 +986,7 @@ static int CmdHFiClassSim(const char *Cmd) { size_t datalen = NUM_CSNS * MAC_ITEM_SIZE; uint8_t *dump = calloc(datalen, sizeof(uint8_t)); - if (!dump) { + if (dump == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1102,7 +1102,7 @@ int read_iclass_csn(bool loop, bool verbose, bool shallow_mod) { free(card); res = PM3_SUCCESS; } else { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); res = PM3_EMALLOC; } } @@ -1263,7 +1263,7 @@ static int CmdHFiClassESave(const char *Cmd) { uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1326,7 +1326,7 @@ static int CmdHFiClassEView(const char *Cmd) { uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memset(dump, 0, bytes); @@ -1418,6 +1418,7 @@ static int iclass_decode_credentials_new_pacs(uint8_t *d) { char *binstr = (char *)calloc((PICOPASS_BLOCK_SIZE * 8) + 1, sizeof(uint8_t)); if (binstr == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -3914,6 +3915,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { keycount = 5000; keyBlock = calloc(1, keycount * 8); if (keyBlock == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -3959,7 +3961,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // allocate memory for the pre calculated macs iclass_premac_t *pre = calloc(keycount, sizeof(iclass_premac_t)); if (pre == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -4021,7 +4023,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { uint32_t tmp_plen = sizeof(iclass_chk_t) + (4 * curr_chunk_cnt); iclass_chk_t *packet = calloc(tmp_plen, sizeof(uint8_t)); if (packet == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); break; } packet->use_credit_key = use_credit_key; @@ -4674,6 +4676,7 @@ static int CmdHFiClassLookUp(const char *Cmd) { keycount = 5000; keyBlock = calloc(1, keycount * 8); if (keyBlock == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfict.c b/client/src/cmdhfict.c index 4432532c5..5a7e6fadd 100644 --- a/client/src/cmdhfict.c +++ b/client/src/cmdhfict.c @@ -520,7 +520,7 @@ static int CmdHfIctCredential(const char *Cmd) { uint16_t sc_size = mfNumBlocksPerSector(ICT_MIFARE_SECTOR) * MFBLOCK_SIZE; uint8_t *data = calloc(sc_size, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfjooki.c b/client/src/cmdhfjooki.c index 246b6b6bf..51f61e619 100644 --- a/client/src/cmdhfjooki.c +++ b/client/src/cmdhfjooki.c @@ -492,7 +492,7 @@ static int CmdHF14AJookiSim(const char *Cmd) { // hf mfu sim... uint8_t *data = calloc(144, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 768a69e25..0ff062532 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -67,7 +67,7 @@ static int decode_and_print_memory(uint16_t card_size, const uint8_t *input_buff // copy input buffer into newly allocated buffer, because the existing code mutates the data inside. uint8_t *data = calloc(card_size, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memcpy(data, input_buffer, card_size); @@ -432,7 +432,7 @@ static int CmdLegicInfo(const char *Cmd) { // allocate receiver buffer uint8_t *data = calloc(card.cardsize, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -494,8 +494,8 @@ static int CmdLegicRdbl(const char *Cmd) { // allocate receiver buffer uint8_t *data = calloc(len, sizeof(uint8_t)); - if (!data) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -643,7 +643,7 @@ static int CmdLegicWrbl(const char *Cmd) { legic_packet_t *payload = calloc(1, sizeof(legic_packet_t) + dlen); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->offset = (offset & 0xFFFF); @@ -724,7 +724,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin legic_packet_t *payload = calloc(1, sizeof(legic_packet_t)); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->offset = (offset & 0xFFFF); @@ -826,7 +826,7 @@ void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) { legic_packet_t *payload = calloc(1, sizeof(legic_packet_t) + len); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } payload->offset = i; @@ -902,7 +902,7 @@ static int CmdLegicDump(const char *Cmd) { legic_packet_t *payload = calloc(1, sizeof(legic_packet_t)); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->offset = 0; @@ -932,8 +932,8 @@ static int CmdLegicDump(const char *Cmd) { uint16_t readlen = resp.data.asDwords[0]; uint8_t *data = calloc(readlen, sizeof(uint8_t)); - if (!data) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1044,7 +1044,7 @@ static int CmdLegicRestore(const char *Cmd) { legic_packet_t *payload = calloc(1, sizeof(legic_packet_t) + len); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(dump); return PM3_EMALLOC; } @@ -1184,7 +1184,7 @@ static int CmdLegicESave(const char *Cmd) { // set up buffer uint8_t *data = calloc(numofbytes, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1253,7 +1253,7 @@ static int CmdLegicEView(const char *Cmd) { uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1317,7 +1317,7 @@ static int CmdLegicEInfo(const char *Cmd) { uint8_t *dump = calloc(card_size, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1357,8 +1357,8 @@ static int CmdLegicWipe(const char *Cmd) { // set up buffer uint8_t *data = calloc(card.cardsize, sizeof(uint8_t)); - if (!data) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1382,7 +1382,7 @@ static int CmdLegicWipe(const char *Cmd) { legic_packet_t *payload = calloc(1, sizeof(legic_packet_t) + len); if (payload == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(data); return PM3_EMALLOC; } diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index 290b9ab55..b56a0d34c 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -755,8 +755,8 @@ static int CmdHfLTODump(const char *Cmd) { uint32_t dump_len = CM_MEM_MAX_SIZE; uint8_t *dump = calloc(dump_len, sizeof(uint8_t)); - if (!dump) { - PrintAndLogEx(ERR, "error, cannot allocate memory"); + if (dump == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index aae37bf78..74899cd38 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -753,8 +753,8 @@ static int mf_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userkey if (userkeylen >= MIFARE_KEY_SIZE) { int numKeys = userkeylen / MIFARE_KEY_SIZE; p = realloc(*pkeyBlock, numKeys * MIFARE_KEY_SIZE); - if (!p) { - PrintAndLogEx(FAILED, "cannot allocate memory for Keys"); + if (p == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(*pkeyBlock); return PM3_EMALLOC; } @@ -772,8 +772,8 @@ static int mf_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userkey if (load_default) { // Handle default keys p = realloc(*pkeyBlock, (*pkeycnt + ARRAYLEN(g_mifare_default_keys)) * MIFARE_KEY_SIZE); - if (!p) { - PrintAndLogEx(FAILED, "cannot allocate memory for Keys"); + if (p == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(*pkeyBlock); return PM3_EMALLOC; } @@ -799,8 +799,8 @@ static int mf_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userkey return PM3_EFILE; } else { p = realloc(*pkeyBlock, (*pkeycnt + loaded_numKeys) * MIFARE_KEY_SIZE); - if (!p) { - PrintAndLogEx(FAILED, "cannot allocate memory for Keys"); + if (p == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(keyBlock_tmp); free(*pkeyBlock); return PM3_EMALLOC; @@ -1155,7 +1155,7 @@ static int CmdHF14AMfRdSc(const char *Cmd) { uint8_t *data = calloc(sc_size, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1315,7 +1315,7 @@ static int CmdHF14AMfDump(const char *Cmd) { iso14a_card_select_t card ; uint8_t *mem = calloc(MIFARE_4K_MAX_BYTES, sizeof(uint8_t)); if (mem == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } int res = mfc_read_tag(&card, mem, numSectors, keyFilename); @@ -3290,7 +3290,7 @@ all_found: bytes = block_cnt * MFBLOCK_SIZE; uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(ERR, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(e_sector); free(fptr); return PM3_EMALLOC; @@ -4913,7 +4913,7 @@ static int CmdHF14AMfESave(const char *Cmd) { // reserv memory uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memset(dump, 0, bytes); @@ -4991,7 +4991,7 @@ static int CmdHF14AMfEView(const char *Cmd) { uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -5787,7 +5787,7 @@ static int CmdHF14AMfCSave(const char *Cmd) { uint16_t bytes = block_cnt * MFBLOCK_SIZE; uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -5937,7 +5937,7 @@ static int CmdHF14AMfCView(const char *Cmd) { uint16_t bytes = block_cnt * MFBLOCK_SIZE; uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -7949,6 +7949,7 @@ static int CmdHF14AMfView(const char *Cmd) { UDATA d; d.bytes = calloc(bytes_read, sizeof(uint8_t)); if (d.bytes == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } uint16_t dlen = 0; @@ -8418,7 +8419,7 @@ static int CmdHF14AGen4Load(const char *cmd) { if (fill_from_emulator) { data = calloc(block_cnt * MFBLOCK_SIZE, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -8620,7 +8621,7 @@ static int CmdHF14AGen4View(const char *Cmd) { uint16_t bytes = block_cnt * MFBLOCK_SIZE; uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -8763,7 +8764,7 @@ static int CmdHF14AGen4Save(const char *Cmd) { uint16_t bytes = block_cnt * MFBLOCK_SIZE; uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -10161,10 +10162,10 @@ static int CmdHF14AMfISEN(const char *Cmd) { uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EFAILED; } - if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) { + if (GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false) == false) { PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); free(dump); return PM3_ETIMEOUT; diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 8f9f517e0..4e4c19a57 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -459,11 +459,11 @@ static int mfdes_get_info(mfdes_info_res_t *info) { int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, size_t signature_len) { if (uid == NULL) { - PrintAndLogEx(DEBUG, "UID=NULL"); + PrintAndLogEx(DEBUG, "UID is NULL"); return PM3_EINVARG; } if (signature == NULL) { - PrintAndLogEx(DEBUG, "SIGNATURE=NULL"); + PrintAndLogEx(DEBUG, "SIGNATURE is NULL"); return PM3_EINVARG; } @@ -472,7 +472,9 @@ int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, si } static void swap24(uint8_t *data) { - if (data == NULL) return; + if (data == NULL) { + return; + } uint8_t tmp = data[0]; data[0] = data[2]; data[2] = tmp; @@ -4850,7 +4852,7 @@ static int DesfileReadFileAndPrint(DesfireContext_t *dctx, uint8_t *resp = calloc(DESFIRE_BUFFER_SIZE, 1); if (resp == NULL) { - PrintAndLogEx(ERR, "Desfire calloc " _RED_("error")); + PrintAndLogEx(WARNING, "Failed to allocate memory"); DropField(); return PM3_EMALLOC; } diff --git a/client/src/cmdhfmfhard.c b/client/src/cmdhfmfhard.c index d25bcf37e..8381a4c8d 100644 --- a/client/src/cmdhfmfhard.c +++ b/client/src/cmdhfmfhard.c @@ -708,12 +708,22 @@ static int add_nonce(uint32_t nonce_enc, uint8_t par_enc) { } else { // add new entry at end of existing list. p2 = p2->next = calloc(1, sizeof(noncelistentry_t)); } + + if (p2 == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + } + } else if ((p1->nonce_enc & 0x00ff0000) != (nonce_enc & 0x00ff0000)) { // found distinct 2nd byte. Need to insert. if (p2 == NULL) { // need to insert at start of list p2 = nonces[first_byte].first = calloc(1, sizeof(noncelistentry_t)); } else { p2 = p2->next = calloc(1, sizeof(noncelistentry_t)); } + + if (p2 == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + } + } else { // we have seen this 2nd byte before. Nothing to add or insert. return (0); } diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 7893860f9..8437d72da 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -1676,7 +1676,7 @@ static int CmdHFMFPChk(const char *Cmd) { char *fptr = calloc(sizeof(char) * (strlen("hf-mfp-") + strlen("-key")) + card.uidlen * 2 + 1, sizeof(uint8_t)); if (fptr == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } strcpy(fptr, "hf-mfp-"); @@ -1742,7 +1742,7 @@ static int CmdHFMFPDump(const char *Cmd) { // read card uint8_t *mem = calloc(MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, sizeof(uint8_t)); if (mem == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index fad468193..b98d6faa1 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -307,7 +307,7 @@ static const char *getUlev1CardSizeStr(uint8_t fsize) { int ul_read_uid(uint8_t *uid) { if (uid == NULL) { - PrintAndLogEx(WARNING, "NUll parameter UID"); + PrintAndLogEx(WARNING, "UID is NULL"); return PM3_ESOFT; } // read uid from tag @@ -1573,7 +1573,7 @@ static char *mfu_generate_filename(const char *prefix, const char *suffix) { char *fptr = calloc(sizeof(char) * (strlen(prefix) + strlen(suffix)) + sizeof(card.uid) * 2 + 1, sizeof(uint8_t)); if (fptr == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } strcpy(fptr, prefix); @@ -1596,7 +1596,7 @@ static int mfu_dump_tag(uint16_t pages, void **pdata, uint16_t *len) { *pdata = calloc(maxbytes, sizeof(uint8_t)); if (*pdata == NULL) { - PrintAndLogEx(FAILED, "error, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); res = PM3_EMALLOC; goto out; } @@ -1867,7 +1867,7 @@ static int mfu_fingerprint(uint64_t tagtype, bool hasAuthKey, const uint8_t *aut maxbytes = ((maxbytes / MFU_BLOCK_SIZE) + 1) * MFU_BLOCK_SIZE; data = calloc(maxbytes, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); res = PM3_EMALLOC; goto out; } @@ -5304,7 +5304,7 @@ static int GetMfuDumpFromEMul(mfu_dump_t **buf) { mfu_dump_t *dump = calloc(1, sizeof(mfu_dump_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfntag424.c b/client/src/cmdhfntag424.c index f95de59c8..459391196 100644 --- a/client/src/cmdhfntag424.c +++ b/client/src/cmdhfntag424.c @@ -155,13 +155,17 @@ static void ntag424_print_version_information(ntag424_version_information_t *ver if (is_hw) { const char *capacitance = "unknown"; switch (version->sub_type & 0xf) { - case 2: capacitance = "50pF"; - case 8: capacitance = "50pF + Tag Tamper"; + case 2: + capacitance = "50pF"; + case 8: + capacitance = "50pF + Tag Tamper"; } const char *modulation = "unknown"; switch ((version->sub_type >> 4) & 0xf) { - case 0: modulation = "strong"; - case 8: modulation = "standard"; + case 0: + modulation = "strong"; + case 8: + modulation = "standard"; } PrintAndLogEx(INFO, " sub type: " _GREEN_("%02X (capacitance: %s, modulation: %s)"), version->sub_type, capacitance, modulation); } else { @@ -305,7 +309,7 @@ static void ntag424_calc_mac(const ntag424_session_keys_t *session_keys, uint8_t uint8_t *mac_input = (uint8_t *)calloc(mac_input_len, sizeof(uint8_t)); if (mac_input == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } memcpy(mac_input, mac_input_header, sizeof(mac_input_header)); diff --git a/client/src/cmdhftopaz.c b/client/src/cmdhftopaz.c index 3815706d5..05069a35b 100644 --- a/client/src/cmdhftopaz.c +++ b/client/src/cmdhftopaz.c @@ -362,6 +362,7 @@ static int topaz_set_cc_dynamic(const uint8_t *data) { topaz_tag.size = memsize; topaz_tag.dynamic_memory = calloc(memsize - TOPAZ_STATIC_MEMORY, sizeof(uint8_t)); if (topaz_tag.dynamic_memory == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } return PM3_SUCCESS; @@ -543,7 +544,7 @@ static void topaz_print_control_TLVs(uint8_t *memory) { if (old == NULL) { new = topaz_tag.dynamic_lock_areas = (dynamic_lock_area_t *) calloc(sizeof(dynamic_lock_area_t), sizeof(uint8_t)); if (new == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } } else { @@ -552,7 +553,7 @@ static void topaz_print_control_TLVs(uint8_t *memory) { } new = old->next = (dynamic_lock_area_t *) calloc(sizeof(dynamic_lock_area_t), sizeof(uint8_t)); if (new == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } } diff --git a/client/src/cmdhfvas.c b/client/src/cmdhfvas.c index 494868d0f..9ce6e70e4 100644 --- a/client/src/cmdhfvas.c +++ b/client/src/cmdhfvas.c @@ -115,7 +115,7 @@ 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"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhfxerox.c b/client/src/cmdhfxerox.c index 911569499..ad13a0dca 100644 --- a/client/src/cmdhfxerox.c +++ b/client/src/cmdhfxerox.c @@ -635,7 +635,7 @@ static int read_xerox_block(iso14b_card_select_t *card, uint8_t blockno, uint8_t uint8_t approx_len = (2 + card->uidlen + 1); iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + approx_len); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index e4d017684..7dd2cee2f 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -687,8 +687,8 @@ static int CmdReadmem(const char *Cmd) { CLIParserFree(ctx); uint8_t *buffer = calloc(len, sizeof(uint8_t)); - if (!buffer) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + if (buffer == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 0f63bee43..5a2278859 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -474,7 +474,7 @@ int CmdFlexdemod(const char *Cmd) { int *data = calloc(g_GraphTraceLen, sizeof(int)); if (data == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memcpy(data, g_GraphBuffer, g_GraphTraceLen); @@ -760,7 +760,7 @@ static int lf_read_internal(bool realtime, bool verbose, uint64_t samples) { if (realtime) { uint8_t *realtimeBuf = calloc(samples, sizeof(uint8_t)); if (realtimeBuf == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -887,7 +887,7 @@ int lf_sniff(bool realtime, bool verbose, uint64_t samples) { if (realtime) { uint8_t *realtimeBuf = calloc(samples, sizeof(uint8_t)); if (realtimeBuf == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdlfawid.c b/client/src/cmdlfawid.c index 8f2acc151..9e330844a 100644 --- a/client/src/cmdlfawid.c +++ b/client/src/cmdlfawid.c @@ -60,7 +60,7 @@ static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uin lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + bs_len); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->fchigh = 10; @@ -151,7 +151,7 @@ int demodAWID(bool verbose) { (void) verbose; // unused so far uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(DEBUG, "DEBUG: Error - AWID failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -407,9 +407,8 @@ static int CmdAWIDClone(const char *Cmd) { verify_values(&fmtlen, &fc, &cn); uint8_t *bits = calloc(96, sizeof(uint8_t)); - if (bits == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -489,7 +488,7 @@ static int CmdAWIDSim(const char *Cmd) { // 96 --- Bitstream length: 96-bits == 12 bytes lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->fchigh = 10; diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index d7b4b3b3f..c3034f98f 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -859,7 +859,7 @@ static int CmdFdxBSim(const char *Cmd) { uint8_t *bs = calloc(128, sizeof(uint8_t)); if (bs == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bs) != PM3_SUCCESS) { @@ -871,7 +871,7 @@ static int CmdFdxBSim(const char *Cmd) { // 32, no STT, BIPHASE INVERTED == diphase lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + 128); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(bs); return PM3_EMALLOC; } diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index 3052b2619..b4955290d 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -364,7 +364,7 @@ static int CmdGallagherSim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdlfguard.c b/client/src/cmdlfguard.c index b06e28ea8..9275a5e32 100644 --- a/client/src/cmdlfguard.c +++ b/client/src/cmdlfguard.c @@ -292,7 +292,7 @@ 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."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } if (getGuardBits(xorval, fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { @@ -388,7 +388,7 @@ static int CmdGuardSim(const char *Cmd) { // Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase) lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 2; diff --git a/client/src/cmdlfhid.c b/client/src/cmdlfhid.c index 02b266a87..1db507df4 100644 --- a/client/src/cmdlfhid.c +++ b/client/src/cmdlfhid.c @@ -120,7 +120,7 @@ int demodHID(bool verbose) { uint8_t *bits = calloc(g_GraphTraceLen, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } size_t size = getFromGraphBuffer(bits); diff --git a/client/src/cmdlfhitag.c b/client/src/cmdlfhitag.c index 4d599904a..8e3a0b808 100644 --- a/client/src/cmdlfhitag.c +++ b/client/src/cmdlfhitag.c @@ -83,8 +83,8 @@ static int CmdLFHitagList(const char *Cmd) { return CmdTraceListAlias(Cmd, "lf hitag", "ht2"); /* uint8_t *got = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); - if (!got) { - PrintAndLogEx(WARNING, "Cannot allocate memory for trace"); + if (got == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -100,7 +100,7 @@ static int CmdLFHitagList(const char *Cmd) { if (traceLen > PM3_CMD_DATA_SIZE) { uint8_t *p = realloc(got, traceLen); if (p == NULL) { - PrintAndLogEx(WARNING, "Cannot allocate memory for trace"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(got); return PM3_EMALLOC; } @@ -589,6 +589,7 @@ void hitag2_annotate_plain(char *exp, size_t size, const uint8_t *cmd, uint8_t c char *binstr = (char *)calloc((cmdsize * 8) + 1, sizeof(uint8_t)); if (binstr == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -656,6 +657,7 @@ void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, char *binstr = (char *)calloc((cmdsize * 8) + 1, sizeof(uint8_t)); if (binstr == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -1680,7 +1682,7 @@ static int CmdLFHitagEload(const char *Cmd) { lf_hitag_t *payload = calloc(1, sizeof(lf_hitag_t) + bytes_read); if (payload == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(dump); return PM3_EMALLOC; } @@ -1728,7 +1730,7 @@ static int CmdLFHitagEview(const char *Cmd) { // reserve memory uint8_t *dump = calloc(bytes, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1843,7 +1845,7 @@ static int CmdLFHitag2PWMDemod(const char *Cmd) { uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(INFO, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index c7be951db..87ad4d833 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -176,7 +176,7 @@ static int sendTry(uint8_t fc, uint16_t cn, uint32_t delay, bool fmt4041x, bool // indala PSK, clock 32, carrier 0 lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->carrier = 2; @@ -409,7 +409,7 @@ static int CmdIndalaDemodAlt(const char *Cmd) { // under normal conditions it's < 2048 uint8_t *data = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } size_t datasize = getFromGraphBuffer(data); @@ -761,7 +761,7 @@ static int CmdIndalaSim(const char *Cmd) { // indala PSK, clock 32, carrier 0 lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->carrier = 2; diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 12cd68520..865b2b74a 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -68,7 +68,7 @@ int demodIOProx(bool verbose) { int idx = 0, retval = PM3_SUCCESS; uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } size_t size = getFromGraphBuffer(bits); @@ -252,7 +252,7 @@ static int CmdIOProxSim(const char *Cmd) { // size --- 64 bits == 8 bytes lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->fchigh = 10; diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index cfd0752eb..fc599a646 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -347,7 +347,7 @@ static int CmdKeriSim(const char *Cmd) { lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->carrier = 2; diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index acb162b3e..ac6bea204 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -540,7 +540,7 @@ static int CmdLFNedapSim(const char *Cmd) { // NEDAP, Biphase = 2, clock 64, inverted, (DIPhase == inverted BIphase) lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + g_DemodBufferLen); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 2; diff --git a/client/src/cmdlfnexwatch.c b/client/src/cmdlfnexwatch.c index 3c42465da..b1a162817 100644 --- a/client/src/cmdlfnexwatch.c +++ b/client/src/cmdlfnexwatch.c @@ -424,13 +424,13 @@ static int CmdNexWatchClone(const char *Cmd) { uint8_t *res_shifted = calloc(96, sizeof(uint8_t)); if (res_shifted == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed for res_shifted"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } uint8_t *res = calloc(96, sizeof(uint8_t)); if (res == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed for res"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(res_shifted); return PM3_EMALLOC; } @@ -557,7 +557,7 @@ static int CmdNexWatchSim(const char *Cmd) { lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed for payload"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->carrier = 2; diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index 1dfedac6e..2a0fbd2b2 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -200,7 +200,7 @@ static int CmdNoralsyClone(const char *Cmd) { uint8_t *bits = calloc(96, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } if (getnoralsyBits(id, year, bits) != PM3_SUCCESS) { @@ -262,7 +262,7 @@ static int CmdNoralsySim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed."); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdlfpac.c b/client/src/cmdlfpac.c index 2516d7c06..757fd9051 100644 --- a/client/src/cmdlfpac.c +++ b/client/src/cmdlfpac.c @@ -369,7 +369,7 @@ static int CmdPacSim(const char *Cmd) { // NRZ sim. lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->invert = 0; diff --git a/client/src/cmdlfparadox.c b/client/src/cmdlfparadox.c index 2205fb6a3..dae518311 100644 --- a/client/src/cmdlfparadox.c +++ b/client/src/cmdlfparadox.c @@ -105,7 +105,7 @@ int demodParadox(bool verbose, bool oldChksum) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } size_t size = getFromGraphBuffer(bits); @@ -447,7 +447,7 @@ static int CmdParadoxSim(const char *Cmd) { lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->fchigh = high; diff --git a/client/src/cmdlfpresco.c b/client/src/cmdlfpresco.c index f430d22ea..a3f1c89e2 100644 --- a/client/src/cmdlfpresco.c +++ b/client/src/cmdlfpresco.c @@ -334,7 +334,7 @@ static int CmdPrescoSim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdlfpyramid.c b/client/src/cmdlfpyramid.c index c7e268030..9e24c319b 100644 --- a/client/src/cmdlfpyramid.c +++ b/client/src/cmdlfpyramid.c @@ -45,7 +45,7 @@ int demodPyramid(bool verbose) { //raw fsk demod no manchester decoding no start bit finding just get binary from wave uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } size_t size = getFromGraphBuffer(bits); @@ -305,7 +305,7 @@ static int CmdPyramidClone(const char *Cmd) { uint8_t *bs = calloc(128, sizeof(uint8_t)); if (bs == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -429,7 +429,7 @@ static int CmdPyramidSim(const char *Cmd) { // Pyramid uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0 lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->fchigh = 10; diff --git a/client/src/cmdlfsecurakey.c b/client/src/cmdlfsecurakey.c index fe4d40aab..f4e381e42 100644 --- a/client/src/cmdlfsecurakey.c +++ b/client/src/cmdlfsecurakey.c @@ -271,7 +271,7 @@ static int CmdSecurakeySim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdlft55xx.c b/client/src/cmdlft55xx.c index 04afdc32b..7da9967f2 100644 --- a/client/src/cmdlft55xx.c +++ b/client/src/cmdlft55xx.c @@ -346,7 +346,7 @@ static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, u char *r3 = (char *)calloc(r_count, sizeof(uint8_t)); if (r0 == NULL || r1 == NULL || r2 == NULL || r3 == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(r0); free(r1); free(r2); @@ -367,7 +367,7 @@ static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, u if (show == T55XX_DLMODE_ALL) { char *r4 = (char *)calloc(r_count, sizeof(uint8_t)); if (r4 == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(r0); free(r1); free(r2); @@ -3200,7 +3200,7 @@ static int CmdResetRead(const char *Cmd) { uint16_t gotsize = g_pm3_capabilities.bigbuf_size - 1; uint8_t *got = calloc(gotsize, sizeof(uint8_t)); if (got == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdlfviking.c b/client/src/cmdlfviking.c index 6706dd361..83f34862a 100644 --- a/client/src/cmdlfviking.c +++ b/client/src/cmdlfviking.c @@ -219,7 +219,7 @@ static int CmdVikingSim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdlfvisa2000.c b/client/src/cmdlfvisa2000.c index 0cb29f446..7de1e9334 100644 --- a/client/src/cmdlfvisa2000.c +++ b/client/src/cmdlfvisa2000.c @@ -277,7 +277,7 @@ static int CmdVisa2kSim(const char *Cmd) { lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->encoding = 1; diff --git a/client/src/cmdmain.c b/client/src/cmdmain.c index da5770e1f..25bf6cce8 100644 --- a/client/src/cmdmain.c +++ b/client/src/cmdmain.c @@ -60,7 +60,7 @@ static void AppendDate(char *s, size_t slen, const char *fmt) { ct = gmtime_r(&now, &tm_buf); #endif if (ct == NULL) { - PrintAndLogEx(ERR, "gmtime failed"); + PrintAndLogEx(WARNING, "gmtime failed"); return; } diff --git a/client/src/cmdpiv.c b/client/src/cmdpiv.c index 423dcfdab..dc4f0e87d 100644 --- a/client/src/cmdpiv.c +++ b/client/src/cmdpiv.c @@ -471,7 +471,7 @@ static void piv_print_fascn(const uint8_t *buf, const size_t len, int level) { static bool piv_tag_dump(const struct tlv *tlv, int level) { if (tlv == NULL) { - PrintAndLogEx(FAILED, "NULL"); + PrintAndLogEx(FAILED, "tlv is NULL"); return false; } @@ -559,6 +559,7 @@ static void PrintTLVFromBuffer(const uint8_t *buf, size_t len) { } struct tlvdb_root *root = calloc(1, sizeof(*root) + len); if (root == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } root->len = len; @@ -597,7 +598,7 @@ static int PivGetData(Iso7816CommandChannel channel, const uint8_t tag[], size_t size_t capacity = PM3_CMD_DATA_SIZE; struct tlvdb_root *root = calloc(1, sizeof(*root) + capacity); if (root == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } root->len = 0; @@ -629,7 +630,7 @@ static int PivGetData(Iso7816CommandChannel channel, const uint8_t tag[], size_t capacity += PM3_CMD_DATA_SIZE; struct tlvdb_root *new_root = realloc(root, sizeof(*root) + capacity); if (new_root == NULL) { - PrintAndLogEx(FAILED, "Running out of memory while re-allocating buffer"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); //free(root); tlvdb_root_free(root); return PM3_EMALLOC; diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index e47d7f85a..ed515a04a 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -50,7 +50,9 @@ static int smart_loadjson(const char *preferredName, json_t **root) { json_error_t error; - if (preferredName == NULL) return 1; + if (preferredName == NULL) { + return 1; + } char *path; int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, ".json", false); @@ -365,7 +367,7 @@ static int smart_responseEx(uint8_t *out, int maxoutlen, bool verbose) { uint8_t cmd_getresp[] = {0x00, ISO7816_GET_RESPONSE, 0x00, 0x00, len}; smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(cmd_getresp)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); goto out; } payload->flags = SC_RAW | SC_LOG; @@ -457,7 +459,7 @@ static int CmdSmartRaw(const char *Cmd) { smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + dlen); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->len = dlen; @@ -487,7 +489,7 @@ static int CmdSmartRaw(const char *Cmd) { uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(DEBUG, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(payload); return PM3_EMALLOC; } @@ -749,7 +751,7 @@ static int CmdSmartInfo(const char *Cmd) { // convert bytes to str. char *hexstr = calloc((card.atr_len << 1) + 1, sizeof(uint8_t)); if (hexstr == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -823,7 +825,7 @@ static int CmdSmartReader(const char *Cmd) { // convert bytes to str. char *hexstr = calloc((card->atr_len << 1) + 1, sizeof(uint8_t)); if (hexstr == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -908,7 +910,7 @@ static void smart_brute_prim(void) { uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -925,7 +927,7 @@ static void smart_brute_prim(void) { smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + 5); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(buf); return; } @@ -950,7 +952,7 @@ static int smart_brute_sfi(bool decodeTLV) { uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 1; } @@ -976,7 +978,7 @@ static int smart_brute_sfi(bool decodeTLV) { smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(READ_RECORD)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(buf); return 1; } @@ -1026,7 +1028,7 @@ static void smart_brute_options(bool decodeTLV) { uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -1035,7 +1037,7 @@ static void smart_brute_options(bool decodeTLV) { smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(GET_PROCESSING_OPTIONS)); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(buf); return; } @@ -1093,7 +1095,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) { uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1137,7 +1139,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) { size_t aidlen = strlen(aid); caid = calloc(8 + 2 + aidlen + 1, sizeof(uint8_t)); if (caid == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); json_decref(root); free(buf); return PM3_EMALLOC; @@ -1152,7 +1154,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) { smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + hexlen); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); json_decref(root); free(buf); return PM3_EMALLOC; @@ -1508,7 +1510,7 @@ int ExchangeAPDUSC(bool verbose, uint8_t *datain, int datainlen, bool activateCa smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + datainlen); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } payload->flags = (SC_RAW_T0 | SC_LOG); diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index f6d7fff6a..0e83bf128 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -1103,7 +1103,7 @@ static int download_trace(void) { gs_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (gs_trace == NULL) { - PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1126,7 +1126,7 @@ static int download_trace(void) { free(gs_trace); gs_trace = calloc(gs_traceLen, sizeof(uint8_t)); if (gs_trace == NULL) { - PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdwiegand.c b/client/src/cmdwiegand.c index e6ae43629..d29521d53 100644 --- a/client/src/cmdwiegand.c +++ b/client/src/cmdwiegand.c @@ -45,7 +45,7 @@ static int wiegand_new_pacs(uint8_t *padded_pacs, uint8_t plen) { char *binstr = (char *)calloc((PACS_EXTRA_LONG_FORMAT * 8) + 1, sizeof(uint8_t)); if (binstr == NULL) { - PrintAndLogEx(INFO, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/comms.c b/client/src/comms.c index 7c55cacd5..e2684100f 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -1132,7 +1132,9 @@ bool WaitForResponse(uint32_t cmd, PacketResponseNG *response) { */ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint32_t start_index, uint8_t *data, uint32_t datalen, PacketResponseNG *response, size_t ms_timeout, bool show_warning) { - if (dest == NULL) return false; + if (dest == NULL) { + return false; + } // init to ZERO PacketResponseNG resp; diff --git a/client/src/crypto/asn1dump.c b/client/src/crypto/asn1dump.c index 32dc8f051..ba6ad1f2b 100644 --- a/client/src/crypto/asn1dump.c +++ b/client/src/crypto/asn1dump.c @@ -364,7 +364,7 @@ static void asn1_tag_dump_object_id(const struct tlv *tlv, const struct asn1_tag bool asn1_tag_dump(const struct tlv *tlv, int level, bool *candump) { if (tlv == NULL) { - PrintAndLogEx(FAILED, "NULL\n"); + PrintAndLogEx(WARNING, "tlv is NULL\n"); return false; } diff --git a/client/src/crypto/asn1utils.c b/client/src/crypto/asn1utils.c index 67392f534..5b73bf6ef 100644 --- a/client/src/crypto/asn1utils.c +++ b/client/src/crypto/asn1utils.c @@ -36,6 +36,7 @@ int ecdsa_asn1_get_signature(uint8_t *signature, size_t signaturelen, uint8_t *r uint8_t *p = calloc(sizeof(uint8_t), signaturelen); if (p == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -253,6 +254,7 @@ int asn1_selftest(void) { uint8_t *d = calloc(n, sizeof(uint8_t)); if (d == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } int len = 0; diff --git a/client/src/emv/crypto_polarssl.c b/client/src/emv/crypto_polarssl.c index b3d42d11a..f39a2d88e 100644 --- a/client/src/emv/crypto_polarssl.c +++ b/client/src/emv/crypto_polarssl.c @@ -65,6 +65,7 @@ static struct crypto_hash *crypto_hash_polarssl_open(enum crypto_algo_hash hash) struct crypto_hash_polarssl *ch = calloc(1, sizeof(*ch)); if (ch == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } @@ -86,6 +87,7 @@ struct crypto_pk_polarssl { static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl) { struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); if (cp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } memset(cp, 0x00, sizeof(*cp)); @@ -114,6 +116,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl) { static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl) { struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); if (cp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } memset(cp, 0x00, sizeof(*cp)); @@ -177,6 +180,7 @@ static int myrand(void *rng_state, unsigned char *output, size_t len) { static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl) { struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); if (cp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } memset(cp, 0x00, sizeof(*cp)); @@ -264,7 +268,7 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_ *plen = mbedtls_mpi_size(&cp->ctx.N); result = calloc(1, *plen); if (result == NULL) { - PrintAndLogEx(WARNING, "Error allocating memory for parameter"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 0; } memset(result, 0x00, *plen); @@ -280,7 +284,7 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_ *plen = mbedtls_mpi_size(&cp->ctx.E); result = calloc(1, *plen); if (result == NULL) { - PrintAndLogEx(WARNING, "Error allocating memory for parameter"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 0; } memset(result, 0x00, *plen); diff --git a/client/src/emv/emv_pk.c b/client/src/emv/emv_pk.c index 19ccf1e4f..eacd3db36 100644 --- a/client/src/emv/emv_pk.c +++ b/client/src/emv/emv_pk.c @@ -170,6 +170,7 @@ static ssize_t emv_pk_read_string(char *buf, size_t buflen, char *str, size_t si struct emv_pk *emv_pk_parse_pk(char *buf, size_t buflen) { struct emv_pk *r = calloc(1, sizeof(*r)); if (r == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } ssize_t l; @@ -273,6 +274,7 @@ char *emv_pk_dump_pk(const struct emv_pk *pk) { size_t outsize = 1048; // should be enough char *out = calloc(1, outsize); // should be enough if (out == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } diff --git a/client/src/emv/emv_pki.c b/client/src/emv/emv_pki.c index ed30917e0..7ab221637 100644 --- a/client/src/emv/emv_pki.c +++ b/client/src/emv/emv_pki.c @@ -347,7 +347,7 @@ unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) { *sdatl_len = len; unsigned char *value = calloc(1, len); if (value == NULL) { - PrintAndLogEx(WARNING, "ERROR: Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } memcpy(value, buf, len); diff --git a/client/src/emv/emv_tags.c b/client/src/emv/emv_tags.c index 9536ce66a..2c5aeedc9 100644 --- a/client/src/emv/emv_tags.c +++ b/client/src/emv/emv_tags.c @@ -790,7 +790,7 @@ static void emv_tag_dump_afl(const struct tlv *tlv, const struct emv_tag *tag, i bool emv_tag_dump(const struct tlv *tlv, int level) { if (tlv == NULL) { - PrintAndLogEx(FAILED, "NULL"); + PrintAndLogEx(WARNING, "tlv is NULL"); return false; } diff --git a/client/src/flash.c b/client/src/flash.c index d5e2b2fa1..ff14309a0 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -287,8 +287,8 @@ int flash_load(flash_file_t *ctx, bool force) { } ctx->elf = calloc(fsize + 1, sizeof(uint8_t)); - if (!ctx->elf) { - PrintAndLogEx(ERR, "Error, cannot allocate memory"); + if (ctx->elf == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); res = PM3_EMALLOC; fclose(fd); goto fail; diff --git a/client/src/graph.c b/client/src/graph.c index 394d3023e..80c1e4dc0 100644 --- a/client/src/graph.c +++ b/client/src/graph.c @@ -221,7 +221,7 @@ void convertGraphFromBitstreamEx(int hi, int low) { uint8_t *bits = calloc(g_GraphTraceLen, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(DEBUG, "ERR: convertGraphFromBitstreamEx, failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -470,20 +470,21 @@ bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge) { void add_temporary_marker(uint32_t position, const char *label) { if (g_TempMarkerSize == 0) { //Initialize the marker array + g_TempMarkers = (marker_t *)calloc(1, sizeof(marker_t)); - if (g_TempMarkers == NULL) { //Unable to allocate memory for the marker array - PrintAndLogEx(FAILED, "Unable to allocate memory for the temporary marker array!"); + if (g_TempMarkers == NULL) { // Unable to allocate memory for the marker array + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } - } else { //add more space to the marker array using realloc() - marker_t *temp = (marker_t *)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t))); + } else { //add more space to the marker array using realloc() + + marker_t *temp = (marker_t *)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t))); if (temp == NULL) { //Unable to reallocate memory for a new marker - PrintAndLogEx(FAILED, "Unable to allocate memory for a new temporary marker!"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(temp); return; } else { - //Set g_TempMarkers to the new pointer g_TempMarkers = temp; } } @@ -492,7 +493,7 @@ void add_temporary_marker(uint32_t position, const char *label) { char *markerLabel = (char *)calloc(1, strlen(label) + 1); if (markerLabel == NULL) { - PrintAndLogEx(FAILED, "Unable to allocate memory for marker label!"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } strcpy(markerLabel, label); @@ -521,7 +522,7 @@ buffer_savestate_t save_buffer32(uint32_t *src, size_t length) { //calloc the memory needed uint32_t *savedBuffer = (uint32_t *)calloc(length, sizeof(uint32_t)); if (savedBuffer == NULL) { - PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); buffer_savestate_t bst = {0}; return bst; } @@ -543,7 +544,7 @@ buffer_savestate_t save_bufferS32(int32_t *src, size_t length) { //calloc the memory needed uint32_t *savedBuffer = (uint32_t *)calloc(length, (sizeof(uint32_t))); if (savedBuffer == NULL) { - PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); buffer_savestate_t bst = {0}; return bst; } @@ -577,7 +578,7 @@ buffer_savestate_t save_buffer8(uint8_t *src, size_t length) { // calloc the memory needed uint32_t *savedBuffer = (uint32_t *)calloc(buffSize, sizeof(uint32_t)); if (savedBuffer == NULL) { - PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); buffer_savestate_t bst = {0}; return bst; } diff --git a/client/src/iso7816/apduinfo.c b/client/src/iso7816/apduinfo.c index b7d77aca9..da9375618 100644 --- a/client/src/iso7816/apduinfo.c +++ b/client/src/iso7816/apduinfo.c @@ -438,12 +438,17 @@ int APDUDecode(uint8_t *data, int len, APDU_t *apdu) { } int APDUEncode(APDU_t *apdu, uint8_t *data, int *len) { - if (len) + if (len) { *len = 0; - if (apdu == NULL) + } + + if (apdu == NULL) { return 1; - if (apdu->le > 0x10000) + } + + if (apdu->le > 0x10000) { return 1; + } size_t dptr = 0; data[dptr++] = apdu->cla; diff --git a/client/src/loclass/cipher.c b/client/src/loclass/cipher.c index 93fb33bc7..5aed6c589 100644 --- a/client/src/loclass/cipher.c +++ b/client/src/loclass/cipher.c @@ -263,7 +263,7 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke uint8_t div_key[8]; address_data = (uint8_t *) calloc(address_data_size, sizeof(uint8_t)); if (address_data == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed\n"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } diff --git a/client/src/loclass/cipherutils.c b/client/src/loclass/cipherutils.c index c5ca105a8..83b23c698 100644 --- a/client/src/loclass/cipherutils.c +++ b/client/src/loclass/cipherutils.c @@ -132,7 +132,7 @@ void printarr(const char *name, uint8_t *arr, int len) { size_t outsize = 40 + strlen(name) + len * 5; char *output = calloc(outsize, sizeof(char)); if (output == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } cx = snprintf(output, outsize, "uint8_t %s[] = {", name); diff --git a/client/src/loclass/elite_crack.c b/client/src/loclass/elite_crack.c index c2efaa313..01ffe7b29 100644 --- a/client/src/loclass/elite_crack.c +++ b/client/src/loclass/elite_crack.c @@ -367,7 +367,7 @@ static void *bf_thread(void *thread_arg) { loclass_thread_ret_t *r = (loclass_thread_ret_t *)calloc(sizeof(loclass_thread_ret_t), sizeof(uint8_t)); if (r == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); pthread_exit(NULL); } @@ -727,7 +727,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { size_t itemsize = sizeof(loclass_dumpdata_t); loclass_dumpdata_t *attack = (loclass_dumpdata_t *) calloc(itemsize, sizeof(uint8_t)); if (attack == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/loclass/ikeys.c b/client/src/loclass/ikeys.c index d248d758f..9e9c4c5c4 100644 --- a/client/src/loclass/ikeys.c +++ b/client/src/loclass/ikeys.c @@ -551,7 +551,7 @@ void invert_hash0(uint8_t k[8]) { // Initialize an array of pointers to uint64_t (start with one value, initialized to 0) uint64_t *hydra_heads = (uint64_t *)calloc(sizeof(uint64_t), 1); // Start with one uint64_t if (hydra_heads == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } hydra_heads[0] = 0; // Initialize first value to 0 @@ -570,7 +570,7 @@ void invert_hash0(uint8_t k[8]) { // proper realloc pattern uint64_t *ptmp = (uint64_t *)realloc(hydra_heads, new_head * sizeof(uint64_t)); if (ptmp == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(hydra_heads); return; } diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index 08089afe4..7a92e2344 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -554,6 +554,7 @@ static int DesfireExchangeNative(bool activate_field, DesfireContext_t *ctx, uin uint8_t *buf = calloc(DESFIRE_BUFFER_SIZE, 1); if (buf == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -680,6 +681,7 @@ static int DesfireExchangeISONative(bool activate_field, DesfireContext_t *ctx, uint16_t sw = 0; uint8_t *buf = calloc(DESFIRE_BUFFER_SIZE, 1); if (buf == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -802,6 +804,7 @@ static int DesfireExchangeISONative(bool activate_field, DesfireContext_t *ctx, static int DesfireExchangeISO(bool activate_field, DesfireContext_t *ctx, sAPDU_t apdu, uint16_t le, uint8_t *resp, size_t *resplen, uint16_t *sw) { uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, 1); if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -861,6 +864,7 @@ int DesfireExchangeEx(bool activate_field, DesfireContext_t *ctx, uint8_t cmd, u uint8_t *databuf = calloc(DESFIRE_BUFFER_SIZE, 1); if (databuf == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -908,6 +912,7 @@ int DesfireExchange(DesfireContext_t *ctx, uint8_t cmd, uint8_t *data, size_t da int DesfireSelectAID(DesfireContext_t *ctx, uint8_t *aid1, uint8_t *aid2) { if (aid1 == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EINVARG; } @@ -1958,6 +1963,7 @@ static int DesfireCommandEx(DesfireContext_t *dctx, uint8_t cmd, uint8_t *data, uint8_t *xresp = calloc(DESFIRE_BUFFER_SIZE, 1); if (xresp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/mifare/desfiresecurechan.c b/client/src/mifare/desfiresecurechan.c index 85e2d7d94..2b439b1b4 100644 --- a/client/src/mifare/desfiresecurechan.c +++ b/client/src/mifare/desfiresecurechan.c @@ -289,8 +289,10 @@ static bool DesfireISOChannelValidCmd(uint8_t cmd) { static void DesfireSecureChannelEncodeD40(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) { uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, sizeof(uint8_t)); - if (data == NULL) + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; + } memcpy(dstdata, srcdata, srcdatalen); *dstdatalen = srcdatalen; @@ -364,6 +366,7 @@ static void DesfireSecureChannelEncodeEV1(DesfireContext_t *ctx, uint8_t cmd, ui uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, sizeof(uint8_t)); if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -429,8 +432,10 @@ static void DesfireSecureChannelEncodeEV1(DesfireContext_t *ctx, uint8_t cmd, ui static void DesfireSecureChannelEncodeEV2(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) { uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, sizeof(uint8_t)); - if (data == NULL) + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; + } memcpy(dstdata, srcdata, srcdatalen); *dstdatalen = srcdatalen; @@ -472,9 +477,10 @@ static void DesfireSecureChannelEncodeEV2(DesfireContext_t *ctx, uint8_t cmd, ui static void DesfireSecureChannelEncodeLRP(DesfireContext_t *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) { uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, sizeof(uint8_t)); - if (data == NULL) + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; - + } memcpy(dstdata, srcdata, srcdatalen); *dstdatalen = srcdatalen; @@ -538,9 +544,10 @@ void DesfireSecureChannelEncode(DesfireContext_t *ctx, uint8_t cmd, uint8_t *src static void DesfireSecureChannelDecodeD40(DesfireContext_t *ctx, uint8_t *srcdata, size_t srcdatalen, uint8_t respcode, uint8_t *dstdata, size_t *dstdatalen) { uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, sizeof(uint8_t)); - if (data == NULL) + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; - + } memcpy(dstdata, srcdata, srcdatalen); *dstdatalen = srcdatalen; @@ -786,8 +793,10 @@ static void DesfireISODecode(DesfireContext_t *ctx, uint8_t *srcdata, size_t src return; uint8_t *data = calloc(DESFIRE_BUFFER_SIZE, 1); - if (data == NULL) + if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; + } uint8_t maclen = DesfireGetMACLength(ctx); if (DesfireIsAuthenticated(ctx)) { diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index f730b90d4..2a2aed593 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -345,6 +345,7 @@ int mf_check_keys_fast_ex(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastCh // initialize storage for found keys icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t)); if (tmp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -838,6 +839,7 @@ int mf_static_nested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trg // used for mfCheckKeys_file, which needs a header mem = calloc((maxkeysinblock * MIFARE_KEY_SIZE) + 5, sizeof(uint8_t)); if (mem == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(statelists[0].head.slhead); return PM3_EMALLOC; } @@ -854,6 +856,7 @@ int mf_static_nested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trg // used for mfCheckKeys, which adds its own header. mem = calloc((maxkeysinblock * MIFARE_KEY_SIZE), sizeof(uint8_t)); if (mem == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(statelists[0].head.slhead); return PM3_EMALLOC; } @@ -1078,7 +1081,7 @@ int mf_eml_set_mem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtW size_t paylen = sizeof(struct p) + size; struct p *payload = calloc(1, paylen); if (payload == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/nfc/ndef.c b/client/src/nfc/ndef.c index 5c2115f3b..61a032218 100644 --- a/client/src/nfc/ndef.c +++ b/client/src/nfc/ndef.c @@ -1081,7 +1081,7 @@ static int ndefDecodePayload(NDEFHeader_t *ndef, bool verbose) { char *begin = calloc(ndef->TypeLen + 1, sizeof(char)); if (begin == NULL) { - PrintAndLogEx(ERR, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memcpy(begin, ndef->Type, ndef->TypeLen); diff --git a/client/src/preferences.c b/client/src/preferences.c index 204978fd8..37941ed65 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -130,13 +130,13 @@ int preferences_save(void) { char *fn = prefGetFilename(); int fn_len = strlen(fn) + 5; // .bak\0 - // [FILENAME_MAX+sizeof(preferencesFilename)+10] char *backupFilename = (char *)calloc(fn_len, sizeof(uint8_t)); if (backupFilename == NULL) { - PrintAndLogEx(ERR, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(fn); return PM3_EMALLOC; } + snprintf(backupFilename, fn_len, "%s.bak", fn); // remove old backup file diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 59b84fe85..11df8328f 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -655,7 +655,7 @@ static void set_my_user_directory(void) { uint16_t pathLen = FILENAME_MAX; // should be a good starting point char *cwd_buffer = (char *)calloc(pathLen, sizeof(uint8_t)); if (cwd_buffer == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } @@ -664,7 +664,7 @@ static void set_my_user_directory(void) { pathLen += 10; // if buffer was too small add 10 characters and try again char *tmp = realloc(cwd_buffer, pathLen); if (tmp == NULL) { - PrintAndLogEx(WARNING, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(cwd_buffer); return; } @@ -759,7 +759,7 @@ static int dumpmem_to_file(const char *filename, uint32_t addr, uint32_t len, bo uint8_t *buffer = calloc(len, sizeof(uint8_t)); if (buffer == NULL) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/uart/uart_posix.c b/client/src/uart/uart_posix.c index f1601fcb2..7e569a97a 100644 --- a/client/src/uart/uart_posix.c +++ b/client/src/uart/uart_posix.c @@ -86,7 +86,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient) { serial_port_unix_t_t *sp = calloc(sizeof(serial_port_unix_t_t), sizeof(uint8_t)); if (sp == 0) { - PrintAndLogEx(ERR, "UART failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return INVALID_SERIAL_PORT; } diff --git a/client/src/uart/uart_win32.c b/client/src/uart/uart_win32.c index b96013368..41dd6f732 100644 --- a/client/src/uart/uart_win32.c +++ b/client/src/uart/uart_win32.c @@ -84,11 +84,10 @@ static int uart_reconfigure_timeouts_polling(serial_port sp) { } serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient) { - char acPortName[255] = {0}; - serial_port_windows_t *sp = calloc(sizeof(serial_port_windows_t), sizeof(uint8_t)); - if (sp == 0) { - PrintAndLogEx(WARNING, "UART failed to allocate memory\n"); + serial_port_windows_t *sp = calloc(sizeof(serial_port_windows_t), sizeof(uint8_t)); + if (sp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return INVALID_SERIAL_PORT; } @@ -99,6 +98,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed, bool slient) { g_conn.send_via_local_ip = false; g_conn.send_via_ip = PM3_NONE; + char acPortName[255] = {0}; + char *prefix = str_dup(pcPortName); if (prefix == NULL) { PrintAndLogEx(ERR, "error: string duplication"); diff --git a/client/src/ui.c b/client/src/ui.c index d8c532ff4..4aed59a45 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -85,6 +85,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam size_t pathlen = strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1; char *path = calloc(pathlen, sizeof(char)); if (path == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -120,6 +121,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam pathlen += strlen(subdir); char *tmp = realloc(path, pathlen * sizeof(char)); if (tmp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(path); return PM3_EMALLOC; } @@ -157,6 +159,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam pathlen += strlen(filename); char *tmp = realloc(path, pathlen * sizeof(char)); if (tmp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(path); return PM3_EMALLOC; } @@ -180,7 +183,7 @@ static void fill_grabber(const char *string) { char *tmp = realloc(g_grabbed_output.ptr, g_grabbed_output.size + MAX_PRINT_BUFFER); if (tmp == NULL) { // We leave current g_grabbed_output untouched - PrintAndLogEx(ERR, "Out of memory error in fill_grabber()"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return; } g_grabbed_output.ptr = tmp; @@ -716,7 +719,7 @@ void print_progress(uint64_t count, uint64_t max, barMode_t style) { // +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"); + fprintf(stderr, "Failed to allocate memory\n"); return; } @@ -744,7 +747,7 @@ void print_progress(uint64_t count, uint64_t max, barMode_t style) { 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"); + fprintf(stderr, "Failed to allocate memory\n"); free(bar); return; } diff --git a/client/src/wiegand_formats.c b/client/src/wiegand_formats.c index d41ceaabc..03b0f5501 100644 --- a/client/src/wiegand_formats.c +++ b/client/src/wiegand_formats.c @@ -1671,6 +1671,7 @@ int HIDDumpPACSBits(const uint8_t *const data, const uint8_t length, bool verbos uint8_t pad = data[0]; char *binstr = (char *)calloc((length * 8) + 1, sizeof(uint8_t)); if (binstr == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; }