From 875b3c44b46db8c647b8a69226a512f1587fd75f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 25 Mar 2025 10:12:16 +0100 Subject: [PATCH] unify text - step 1 --- armsrc/Standalone/hf_15sim.c | 4 +- armsrc/Standalone/hf_iceclass.c | 2 +- armsrc/Standalone/hf_legic.c | 6 +- armsrc/Standalone/hf_unisniff.c | 2 +- armsrc/appmain.c | 3 +- armsrc/fpgaloader.c | 4 +- armsrc/i2c.c | 1 - armsrc/i2c_direct.c | 3 +- armsrc/iclass.c | 4 +- armsrc/iso14443a.c | 7 ++- armsrc/iso14443b.c | 1 + armsrc/iso15693.c | 2 +- armsrc/lfsampling.c | 3 +- armsrc/mifarecmd.c | 4 +- armsrc/printf.c | 6 +- armsrc/sam_common.c | 9 +-- armsrc/sam_seos.c | 4 +- client/src/aidsearch.c | 22 ++++--- client/src/atrs.c | 2 +- client/src/cmdanalyse.c | 1 + client/src/cmdcrc.c | 11 ++-- client/src/cmddata.c | 57 +++++++++++-------- client/src/cmdflashmem.c | 11 ++-- client/src/cmdflashmemspiffs.c | 6 +- client/src/cmdhf14a.c | 6 +- client/src/cmdhf14b.c | 16 +++--- client/src/cmdhf15.c | 34 +++++------ client/src/cmdhfcryptorf.c | 9 +-- tools/fpga_compress/fpga_compress.c | 10 ++-- .../crack2/ht2crack2search_multi.c | 4 +- tools/hitag2crack/crack3/ht2crack3.c | 4 +- tools/hitag2crack/crack4/ht2crack4.c | 4 +- tools/hitag2crack/crack5opencl/opencl.c | 2 +- tools/mfc/card_only/nested_util.c | 15 ++--- tools/mfc/card_only/staticnested_0nt.c | 1 + tools/mfc/card_only/staticnested_2nt.c | 1 + tools/mfc/card_reader/mf_nonce_brute.c | 8 +-- tools/mfc/card_reader/mf_trace_brute.c | 2 +- tools/mfd_aes_brute/mfd_aes_brute.c | 2 +- tools/mfd_aes_brute/mfd_multi_brute.c | 2 +- 40 files changed, 167 insertions(+), 128 deletions(-) diff --git a/armsrc/Standalone/hf_15sim.c b/armsrc/Standalone/hf_15sim.c index b156f3b1b..eb5736ca5 100644 --- a/armsrc/Standalone/hf_15sim.c +++ b/armsrc/Standalone/hf_15sim.c @@ -70,7 +70,9 @@ void RunMod(void) { FpgaDownloadAndGo(FPGA_BITSTREAM_HF_15); iso15_tag_t *tag = (iso15_tag_t *) BigBuf_get_EM_addr(); - if (tag == NULL) return; + if (tag == NULL) { + return; + } uint8_t cmd[8] = {0}; int res; diff --git a/armsrc/Standalone/hf_iceclass.c b/armsrc/Standalone/hf_iceclass.c index a47cf6517..c657d2e03 100644 --- a/armsrc/Standalone/hf_iceclass.c +++ b/armsrc/Standalone/hf_iceclass.c @@ -252,7 +252,7 @@ static int reader_attack_mode(void) { uint8_t *dump = BigBuf_malloc(dumplen); if (dump == false) { - Dbprintf("failed to allocate memory"); + Dbprintf("Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/armsrc/Standalone/hf_legic.c b/armsrc/Standalone/hf_legic.c index 58d958c14..a15bb2de3 100644 --- a/armsrc/Standalone/hf_legic.c +++ b/armsrc/Standalone/hf_legic.c @@ -69,16 +69,18 @@ static void save_dump_to_file(legic_card_select_t *p_card) { // legic functions puts it memory in Emulator reserved memory. uint8_t *mem = BigBuf_get_EM_addr(); - char *preferredName = (char *)BigBuf_malloc(30); + char *preferredName = (char *)BigBuf_calloc(30); if (preferredName == NULL) { + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); goto OUT; } sprintf(preferredName, "hf-legic-%02X%02X%02X%02X-dump", p_card->uid[0], p_card->uid[1], p_card->uid[2], p_card->uid[3]); uint16_t preferredNameLen = strlen(preferredName); - char *filename = (char *)BigBuf_malloc(preferredNameLen + 4 + 1 + 10); + char *filename = (char *)BigBuf_calloc(preferredNameLen + 4 + 1 + 10); if (filename == NULL) { + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); goto OUT; } diff --git a/armsrc/Standalone/hf_unisniff.c b/armsrc/Standalone/hf_unisniff.c index be0414a58..fcf1bb48d 100644 --- a/armsrc/Standalone/hf_unisniff.c +++ b/armsrc/Standalone/hf_unisniff.c @@ -201,7 +201,7 @@ void RunMod(void) { // available after filling the trace buffer. char *filename = (char *)BigBuf_calloc(64); if (filename == NULL) { - Dbprintf("failed to allocate memory"); + Dbprintf("Failed to allocate memory"); return; } // Read the config file. Size is limited to defined value so as not to consume diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 6c94c3f91..49005a43d 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -2696,7 +2696,7 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t *buff = BigBuf_malloc(size); if (buff == NULL) { - if (g_dbglevel >= DBG_DEBUG) Dbprintf("Could not allocate buffer"); + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); // Trigger a finish downloading signal with an PM3_EMALLOC reply_ng(CMD_SPIFFS_DOWNLOAD, PM3_EMALLOC, NULL, 0); } else { @@ -2826,6 +2826,7 @@ static void PacketReceived(PacketCommandNG *packet) { uint8_t *em = BigBuf_get_EM_addr(); if (em == NULL) { + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); reply_ng(CMD_SPIFFS_ELOAD, PM3_EMALLOC, NULL, 0); LED_B_OFF(); break; diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index bf7ad765b..d9e941705 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -185,7 +185,9 @@ void FpgaSetupSsc(uint16_t fpga_mode) { // ourselves, not to another buffer). //----------------------------------------------------------------------------- bool FpgaSetupSscDma(uint8_t *buf, uint16_t len) { - if (buf == NULL) return false; + if (buf == NULL) { + return false; + } FpgaDisableSscDma(); AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address diff --git a/armsrc/i2c.c b/armsrc/i2c.c index 2a4b3a648..501ce388e 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -783,7 +783,6 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose) { return false; } - card_ptr->atr_len = 0; memset(card_ptr->atr, 0, sizeof(card_ptr->atr)); diff --git a/armsrc/i2c_direct.c b/armsrc/i2c_direct.c index e40b261a5..909c1ec30 100644 --- a/armsrc/i2c_direct.c +++ b/armsrc/i2c_direct.c @@ -167,9 +167,10 @@ int CmdSmartRaw(const uint8_t prepend, const uint8_t *data, int dlen, uint8_t *o smart_card_raw_t *payload = (smart_card_raw_t *)BigBuf_calloc(sizeof(smart_card_raw_t) + dlen); if (payload == NULL) { - Dbprintf("failed to allocate memory"); + Dbprintf("Failed to allocate memory"); return PM3_EMALLOC; } + payload->len = dlen; memcpy(payload->data, data, dlen); diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 2e2501605..6b79b7012 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1664,9 +1664,9 @@ void iClass_Dump(uint8_t *msg) { iclass_auth_req_t *req = &cmd->req; bool shallow_mod = req->shallow_mod; - uint8_t *dataout = BigBuf_malloc(ICLASS_16KS_SIZE); + uint8_t *dataout = BigBuf_calloc(ICLASS_16KS_SIZE); if (dataout == NULL) { - DbpString("fail to allocate memory"); + DbpString("Failed to allocate memory"); if (req->send_reply) { reply_ng(CMD_HF_ICLASS_DUMP, PM3_EMALLOC, NULL, 0); } diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 6b88d47b9..5165b5cad 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -2407,7 +2407,10 @@ int EmSendCmdEx(uint8_t *resp, uint16_t respLen, bool collision) { } int EmSendPrecompiledCmd(tag_response_info_t *p_response) { - if (p_response == NULL) return 0; + if (p_response == NULL) { + return 0; + } + int ret = EmSendCmd14443aRaw(p_response->modulation, p_response->modulation_n); // do the tracing for the previous reader request and this tag answer: GetParity(p_response->response, p_response->response_n, parity_array); @@ -4032,12 +4035,14 @@ void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid, reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0); return; } + uint8_t *dynamic_modulation_buffer2 = BigBuf_calloc(DYNAMIC_MODULATION_BUFFER2_SIZE); if (dynamic_modulation_buffer2 == NULL) { BigBuf_free_keep_EM(); reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0); return; } + tag_response_info_t dynamic_response_info = { .response = dynamic_response_buffer2, .response_n = 0, diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index 16b1d514b..0ce6c055d 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -1336,6 +1336,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t // The DMA buffer, used to stream samples from the FPGA dmabuf16_t *dma = get_dma16(); if (dma == NULL) { + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index df4f06230..dd3ffa865 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -2129,7 +2129,7 @@ void SimTagIso15693(const uint8_t *uid, uint8_t block_size) { iso15_tag_t *tag = (iso15_tag_t *) BigBuf_get_EM_addr(); if (tag == NULL) { - Dbprintf("Can't allocate emulator memory"); + if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory"); reply_ng(CMD_HF_ISO15693_SIMULATE, PM3_EFAILED, NULL, 0); return; } diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 22fb6411a..ffa1cbcd9 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -739,8 +739,9 @@ void doCotagAcquisition(void) { uint16_t doCotagAcquisitionManchester(uint8_t *dest, uint16_t destlen) { - if (dest == NULL) + if (dest == NULL) { return 0; + } dest[0] = 0; diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 9d6dad95a..ac93d149b 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -398,9 +398,9 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) bool useKey = (arg2 == 1); // UL_C bool usePwd = (arg2 == 2); // UL_EV1/NTAG uint32_t countblocks = 0; - uint8_t *dataout = BigBuf_malloc(CARD_MEMORY_SIZE); + uint8_t *dataout = BigBuf_calloc(CARD_MEMORY_SIZE); if (dataout == NULL) { - Dbprintf("out of memory"); + Dbprintf("Failed to allocate memory"); OnError(1); return; } diff --git a/armsrc/printf.c b/armsrc/printf.c index 7c58ffd82..b2fa19151 100644 --- a/armsrc/printf.c +++ b/armsrc/printf.c @@ -104,11 +104,13 @@ kvsprintf(char const *fmt, void *arg, int radix, va_list ap) { num = 0; d = (char *) arg; - if (fmt == NULL) + if (fmt == NULL) { fmt = "(fmt null)\n"; + } - if (radix < 2 || radix > 36) + if (radix < 2 || radix > 36) { radix = 10; + } for (;;) { padc = ' '; diff --git a/armsrc/sam_common.c b/armsrc/sam_common.c index 567520ee3..ed129134d 100644 --- a/armsrc/sam_common.c +++ b/armsrc/sam_common.c @@ -261,20 +261,17 @@ int sam_get_version(void) { } else { uint8_t *sam_response_an = sam_find_asn1_node(response + 5, 0x8a); if (sam_response_an == NULL) { - if (g_dbglevel >= DBG_ERROR) - DbpString("SAM get response failed"); + if (g_dbglevel >= DBG_ERROR) DbpString("SAM get response failed"); goto error; } uint8_t *sam_version_an = sam_find_asn1_node(sam_response_an, 0x80); if (sam_version_an == NULL) { - if (g_dbglevel >= DBG_ERROR) - DbpString("SAM get version failed"); + if (g_dbglevel >= DBG_ERROR) DbpString("SAM get version failed"); goto error; } uint8_t *sam_build_an = sam_find_asn1_node(sam_response_an, 0x81); if (sam_build_an == NULL) { - if (g_dbglevel >= DBG_ERROR) - DbpString("SAM get firmware ID failed"); + if (g_dbglevel >= DBG_ERROR) DbpString("SAM get firmware ID failed"); goto error; } if (g_dbglevel >= DBG_INFO) { diff --git a/armsrc/sam_seos.c b/armsrc/sam_seos.c index c44115d57..40846705a 100644 --- a/armsrc/sam_seos.c +++ b/armsrc/sam_seos.c @@ -131,8 +131,8 @@ static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t r DbpString("start sam_send_request_iso14a"); } - uint8_t *buf1 = BigBuf_malloc(ISO7816_MAX_FRAME); - uint8_t *buf2 = BigBuf_malloc(ISO7816_MAX_FRAME); + uint8_t *buf1 = BigBuf_calloc(ISO7816_MAX_FRAME); + uint8_t *buf2 = BigBuf_calloc(ISO7816_MAX_FRAME); if (buf1 == NULL || buf2 == NULL) { res = PM3_EMALLOC; goto out; diff --git a/client/src/aidsearch.c b/client/src/aidsearch.c index 48ea3fdc6..98607d199 100644 --- a/client/src/aidsearch.c +++ b/client/src/aidsearch.c @@ -84,16 +84,19 @@ static const char *jsonStrGet(json_t *data, const char *name) { json_t *jstr; jstr = json_object_get(data, name); - if (jstr == NULL) + if (jstr == NULL) { return NULL; + } + if (!json_is_string(jstr)) { PrintAndLogEx(ERR, "`%s` is not a string", name); return NULL; } const char *cstr = json_string_value(jstr); - if (strlen(cstr) == 0) + if (strlen(cstr) == 0) { return NULL; + } return cstr; } @@ -125,17 +128,20 @@ int PrintAIDDescription(json_t *xroot, char *aid, bool verbose) { int retval = PM3_SUCCESS; json_t *root = xroot; - if (root == NULL) + if (root == NULL) { root = AIDSearchInit(verbose); - if (root == NULL) + } + if (root == NULL) { goto out; + } json_t *elm = NULL; size_t maxaidlen = 0; for (size_t elmindx = 0; elmindx < json_array_size(root); elmindx++) { json_t *data = AIDSearchGetElm(root, elmindx); - if (data == NULL) + if (data == NULL) { continue; + } const char *dictaid = jsonStrGet(data, "AID"); if (aidCompare(aid, dictaid)) { // dictaid may be less length than requested aid if (maxaidlen < strlen(dictaid) && strlen(dictaid) <= strlen(aid)) { @@ -145,8 +151,9 @@ int PrintAIDDescription(json_t *xroot, char *aid, bool verbose) { } } - if (elm == NULL) + if (elm == NULL) { goto out; + } // print here const char *vaid = jsonStrGet(elm, "AID"); @@ -175,8 +182,9 @@ int PrintAIDDescription(json_t *xroot, char *aid, bool verbose) { } out: - if (xroot == NULL) + if (xroot == NULL) { AIDSearchFree(root); + } return retval; } diff --git a/client/src/atrs.c b/client/src/atrs.c index e851cf8f9..ee7d50711 100644 --- a/client/src/atrs.c +++ b/client/src/atrs.c @@ -39,7 +39,7 @@ const char *getAtrInfo(const char *atr_str) { char *tmp_atr = calloc(slen, sizeof(uint8_t)); if (tmp_atr == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } diff --git a/client/src/cmdanalyse.c b/client/src/cmdanalyse.c index 161287fc7..9c2d7ec8b 100644 --- a/client/src/cmdanalyse.c +++ b/client/src/cmdanalyse.c @@ -908,6 +908,7 @@ static int CmdAnalyseDemodBuffer(const char *Cmd) { // add 1 for null terminator. uint8_t *data = calloc(len + 1, sizeof(uint8_t)); if (data == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); CLIParserFree(ctx); return PM3_EMALLOC; } diff --git a/client/src/cmdcrc.c b/client/src/cmdcrc.c index 63d9d9ddd..66b826dd5 100644 --- a/client/src/cmdcrc.c +++ b/client/src/cmdcrc.c @@ -57,7 +57,7 @@ static int split(char *str, char *arr[MAX_ARGS]) { int len = endIndex - beginIndex; char *tmp = calloc(len + 1, sizeof(char)); if (tmp == NULL) { - PrintAndLogEx(WARNING, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return wordCnt; } memcpy(tmp, &str[beginIndex], len); @@ -101,7 +101,7 @@ int GetModels(char *Models[], int *count, uint8_t *width) { char *tmp = calloc(size + 1, sizeof(char)); if (tmp == NULL) { - PrintAndLogEx(WARNING, "out of memory?"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 0; } @@ -202,7 +202,7 @@ int GetModels(char *Models[], int *count, uint8_t *width) { //PrintAndLogEx(NORMAL, "Size: %d, %s, count: %d",size,pset.name, Cnt); char *tmp = calloc(size + 1, sizeof(char)); if (tmp == NULL) { - PrintAndLogEx(WARNING, "out of memory?"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 0; } @@ -433,9 +433,10 @@ static int CmdrevengTestC(const char *Cmd) { static char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize) { char *tmp = calloc(len + 1, sizeof(char)); if (tmp == NULL) { - PrintAndLogEx(WARNING, "Memory allocation failed"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return NULL; } + for (uint8_t block = 0; block < (uint8_t)(len / blockSize); block++) { for (size_t i = 0; i < blockSize; i += 2) { tmp[i + (blockSize * block)] = inStr[(blockSize - 1 - i - 1) + (blockSize * block)]; @@ -501,6 +502,7 @@ static int CmdrevengSearch(const char *Cmd) { memset(result, 0, sizeof(result)); char *inCRC = calloc(crcChars + 1, sizeof(char)); if (inCRC == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return 0; } @@ -508,6 +510,7 @@ static int CmdrevengSearch(const char *Cmd) { char *outHex = calloc(dataLen - crcChars + 1, sizeof(char)); if (outHex == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(inCRC); return 0; } diff --git a/client/src/cmddata.c b/client/src/cmddata.c index 592a2a6a2..a8e285b7f 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -94,13 +94,17 @@ static char *commaprint(size_t n) { // set the g_DemodBuffer with given array ofq binary (one bit per byte) void setDemodBuff(const uint8_t *buff, size_t size, size_t start_idx) { - if (buff == NULL) return; + if (buff == NULL) { + return; + } - if (size > MAX_DEMOD_BUF_LEN - start_idx) + if (size > MAX_DEMOD_BUF_LEN - start_idx) { size = MAX_DEMOD_BUF_LEN - start_idx; + } - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { g_DemodBuffer[i] = buff[start_idx++]; + } g_DemodBufferLen = size; } @@ -254,7 +258,7 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h uint8_t *buf = calloc(len, sizeof(uint8_t)); if (buf == NULL) { - PrintAndLogEx(WARNING, "fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } memcpy(buf, g_DemodBuffer, len); @@ -420,7 +424,7 @@ int ASKDemod_ext(int clk, int invert, int maxErr, size_t maxlen, bool amplify, b 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; } @@ -595,7 +599,7 @@ static int Cmdmandecoderaw(const char *Cmd) { uint8_t *bits = calloc(MAX_DEMOD_BUF_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -692,7 +696,7 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) { uint8_t *bits = calloc(MAX_DEMOD_BUF_LEN, sizeof(uint8_t)); if (bits == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -733,7 +737,7 @@ int ASKbiphaseDemod(int offset, int clk, int invert, int maxErr, bool verbose) { uint8_t *bs = calloc(MAX_DEMOD_BUF_LEN, sizeof(uint8_t)); if (bs == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1074,7 +1078,7 @@ static int CmdUndecimate(const char *Cmd) { //We have memory, don't we? int *swap = calloc(MAX_GRAPH_TRACE_LEN, sizeof(int)); if (swap == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } uint32_t g_index = 0, s_index = 0; @@ -1271,7 +1275,7 @@ int FSKrawDemod(uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, bo 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; } @@ -1374,7 +1378,7 @@ int PSKDemod(int clk, int invert, int maxErr, bool verbose) { 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 bitlen = getFromGraphBuffer(bits); @@ -1424,7 +1428,7 @@ int NRZrawDemod(int clk, int invert, int maxErr, bool verbose) { 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; } @@ -1807,7 +1811,7 @@ int CmdHpf(const char *Cmd) { 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); @@ -1915,7 +1919,7 @@ int getSamplesFromBufEx(uint8_t *data, size_t sample_num, uint8_t bits_per_sampl 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); @@ -1991,7 +1995,7 @@ static int CmdLoad(const char *Cmd) { f = fopen(path, "r"); if (f == NULL) { - PrintAndLogEx(WARNING, "couldn't open '%s'", path); + PrintAndLogEx(WARNING, "couldn't open `" _YELLOW_("%s") "`", path); free(path); return PM3_EFILE; } @@ -2005,8 +2009,9 @@ static int CmdLoad(const char *Cmd) { g_GraphBuffer[g_GraphTraceLen] = val[0] - 127; g_GraphTraceLen++; - if (g_GraphTraceLen >= MAX_GRAPH_TRACE_LEN) + if (g_GraphTraceLen >= MAX_GRAPH_TRACE_LEN) { break; + } } } else { char line[80]; @@ -2025,7 +2030,7 @@ static int CmdLoad(const char *Cmd) { if (nofix == false) { 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); @@ -2172,7 +2177,7 @@ int CmdNorm(const char *Cmd) { 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); @@ -2323,7 +2328,7 @@ static int CmdDirectionalThreshold(const char *Cmd) { // set signal properties low/high/mean/amplitude and isnoice detection 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); @@ -2371,7 +2376,7 @@ static int CmdZerocrossings(const char *Cmd) { 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); @@ -2383,8 +2388,9 @@ static int CmdZerocrossings(const char *Cmd) { } static bool data_verify_hex(uint8_t *d, size_t n) { - if (d == NULL) + if (d == NULL) { return false; + } for (size_t i = 0; i < n; i++) { if (isxdigit(d[i]) == false) { @@ -2655,9 +2661,10 @@ static int CmdDataIIR(const char *Cmd) { 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); // set signal properties low/high/mean/amplitude and is_noise detection computeSignalProperties(bits, size); @@ -2974,7 +2981,7 @@ static int CmdDiff(const char *Cmd) { uint8_t *d = calloc(MIFARE_4K_MAX_BYTES, sizeof(uint8_t)); if (d == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -3418,7 +3425,7 @@ static int CmdCenterThreshold(const char *Cmd) { // set signal properties low/high/mean/amplitude and isnoice detection 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); @@ -3468,7 +3475,7 @@ static int CmdEnvelope(const char *Cmd) { 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/cmdflashmem.c b/client/src/cmdflashmem.c index 97596850d..fa88549f7 100644 --- a/client/src/cmdflashmem.c +++ b/client/src/cmdflashmem.c @@ -311,6 +311,7 @@ static int CmdFlashMemLoad(const char *Cmd) { // ICEMAN: not needed when we transite to loadxxxx_safe methods uint8_t *newdata = realloc(data, datalen); if (newdata == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(data); return PM3_EMALLOC; } else { @@ -413,13 +414,13 @@ static int CmdFlashMemDump(const char *Cmd) { CLIParserFree(ctx); uint8_t *dump = calloc(len, sizeof(uint8_t)); - if (!dump) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + if (dump == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } PrintAndLogEx(INFO, "downloading "_YELLOW_("%u")" bytes from flash memory", len); - if (!GetFromDevice(FLASH_MEM, dump, len, offset, NULL, 0, NULL, -1, true)) { + if (GetFromDevice(FLASH_MEM, dump, len, offset, NULL, 0, NULL, -1, true) == false) { PrintAndLogEx(FAILED, "ERROR; downloading from flash memory"); free(dump); return PM3_EFLASH; @@ -566,7 +567,7 @@ static int CmdFlashMemInfo(const char *Cmd) { mbedtls_rsa_context *rsa = (mbedtls_rsa_context *)pkctx.pk_ctx; if (rsa == NULL) { - PrintAndLogEx(FAILED, "failed to allocate rsa context memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } got_private = true; @@ -620,7 +621,7 @@ static int CmdFlashMemInfo(const char *Cmd) { rsa = (mbedtls_rsa_context *)calloc(1, sizeof(mbedtls_rsa_context)); if (rsa == NULL) { - PrintAndLogEx(FAILED, "failed to allocate rsa context memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } mbedtls_rsa_init(rsa, MBEDTLS_RSA_PKCS_V15, 0); diff --git a/client/src/cmdflashmemspiffs.c b/client/src/cmdflashmemspiffs.c index 9dc706d98..8149236af 100644 --- a/client/src/cmdflashmemspiffs.c +++ b/client/src/cmdflashmemspiffs.c @@ -47,7 +47,7 @@ int flashmem_spiffs_load(const char *destfn, const uint8_t *data, size_t datalen flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet); if (payload == NULL) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + PrintAndLogEx(WARNING, "Failed to allocate memory"); ret_val = PM3_EMALLOC; goto out; } @@ -113,7 +113,7 @@ int flashmem_spiffs_download(char *fn, uint8_t fnlen, void **pdest, size_t *dest *pdest = calloc(len, sizeof(uint8_t)); if (*pdest == false) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -413,7 +413,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { uint32_t len = resp.data.asDwords[0]; uint8_t *dump = calloc(len, sizeof(uint8_t)); if (dump == NULL) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index d9dca4450..3174cc47e 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -279,8 +279,9 @@ static int CmdHF14AList(const char *Cmd) { int hf14a_getconfig(hf14a_config *config) { if (!g_session.pm3_present) return PM3_ENOTTY; - if (config == NULL) + if (config == NULL) { return PM3_EINVARG; + } clearCommandBuffer(); @@ -3254,9 +3255,10 @@ int CmdHF14ANdefRead(const char *Cmd) { uint16_t ndef_size = (response[0] << 8) + response[1]; uint16_t offset = 2; + uint8_t *ndef_file = calloc(ndef_size, sizeof(uint8_t)); if (ndef_file == NULL) { - PrintAndLogEx(ERR, "Out of memory error in CmdHF14ANdef(). Aborting...\n"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); DropField(); return PM3_EMALLOC; } diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index e1e9ba741..0d08c3774 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -392,13 +392,13 @@ uint8_t *get_uid_from_filename(const char *filename) { memset(uid, 0, 8); if (strlen(filename) < 23) { - PrintAndLogEx(ERR, "can't get uid from filename '%s'. Expected format is hf-14b-...", filename); + PrintAndLogEx(ERR, "can't get uid from filename `" _YELLOW_("%s") "` expected format is hf-14b-...", filename); return uid; } char *found = strstr(filename, "hf-14b-"); if (found == NULL) { - PrintAndLogEx(ERR, "can't get uid from filename '%s'. Expected format is hf-14b-...", filename); + PrintAndLogEx(ERR, "can't get uid from filename `" _YELLOW_("%s") "` expected format is hf-14b-...", filename); return uid; } @@ -1045,7 +1045,7 @@ static int CmdHF14BRaw(const char *Cmd) { iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + datalen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1250,7 +1250,7 @@ static int write_sr_block(uint8_t blockno, uint8_t datalen, uint8_t *data) { uint8_t psize = sizeof(iso14b_raw_cmd_t) + datalen + 2; iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, psize); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1433,7 +1433,7 @@ bool HF14B_picopass_reader(bool verbose, bool info) { picopass_hdr_t *card = calloc(1, sizeof(picopass_hdr_t)); if (card == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return false; } memcpy(card, resp.data.asBytes, sizeof(picopass_hdr_t)); @@ -1465,7 +1465,7 @@ static bool HF14B_other_reader(bool verbose) { iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + 4); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return false; } packet->flags = (ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_RAW | ISO14B_APPEND_CRC); @@ -1795,7 +1795,7 @@ static int CmdHF14BDump(const char *Cmd) { iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + 2); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } packet->flags = (ISO14B_CONNECT | ISO14B_SELECT_SR); @@ -2235,7 +2235,7 @@ static int handle_14b_apdu(bool chainingin, uint8_t *datain, int datainlen, iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + datainlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "APDU: failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } packet->flags = (ISO14B_APDU); diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index 8b49e4c2f..25ee0a84f 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -426,7 +426,7 @@ static int getUID(bool verbose, bool loop, uint8_t *buf) { uint8_t approxlen = 5; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -668,7 +668,7 @@ static int NxpTestEAS(const uint8_t *uid) { uint8_t approxlen = 3 + HF15_UID_LENGTH + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -723,7 +723,7 @@ static int NxpCheckSig(uint8_t *uid) { uint8_t approxlen = 3 + HF15_UID_LENGTH + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -777,7 +777,7 @@ static int NxpSysInfo(uint8_t *uid) { uint8_t approxlen = 13; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -895,7 +895,7 @@ static int StCheckSig(uint8_t *uid) { uint8_t approxlen = 2 + 8 + 1 + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -998,7 +998,7 @@ static int CmdHF15Info(const char *Cmd) { iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1195,7 +1195,7 @@ static int hf15EmlSetMem(const uint8_t *data, uint16_t count, size_t offset) { size_t paylen = sizeof(struct p) + count; struct p *payload = calloc(1, paylen); if (payload == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1320,7 +1320,7 @@ static int CmdHF15ESave(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; } @@ -1451,7 +1451,7 @@ static int CmdHF15EView(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; } @@ -1726,7 +1726,7 @@ static int CmdHF15WriteDsfid(const char *Cmd) { uint8_t approxlen = 2 + 8 + 1 + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -1846,14 +1846,14 @@ static int CmdHF15Dump(const char *Cmd) { uint8_t approxlen = 2 + 8 + 1 + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } // struct of ISO15693 tag memory (new file format) iso15_tag_t *tag = (iso15_tag_t *)calloc(1, sizeof(iso15_tag_t)); if (tag == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(packet); return PM3_EMALLOC; }; @@ -2098,7 +2098,7 @@ static int CmdHF15Raw(const char *Cmd) { iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + datalen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -2222,7 +2222,7 @@ static int CmdHF15Readmulti(const char *Cmd) { uint8_t approxlen = 2 + 8 + 2 + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -2375,7 +2375,7 @@ static int CmdHF15Readblock(const char *Cmd) { uint8_t approxlen = 2 + 8 + 1 + 2; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -2480,7 +2480,7 @@ static int hf_15_write_blk(const uint8_t *pm3flags, uint16_t flags, const uint8_ uint8_t approxlen = 21; iso15_raw_cmd_t *packet = (iso15_raw_cmd_t *)calloc(1, sizeof(iso15_raw_cmd_t) + approxlen); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -2733,7 +2733,7 @@ static int CmdHF15Restore(const char *Cmd) { uint16_t i = 0; uint8_t *data = calloc(tag->bytesPerPage, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); free(tag); return PM3_EMALLOC; } diff --git a/client/src/cmdhfcryptorf.c b/client/src/cmdhfcryptorf.c index 8b105c705..af703e511 100644 --- a/client/src/cmdhfcryptorf.c +++ b/client/src/cmdhfcryptorf.c @@ -103,8 +103,9 @@ static int CmdHFCryptoRFSniff(const char *Cmd) { static bool get_14b_UID(iso14b_card_select_t *card) { - if (card == NULL) + if (card == NULL) { return false; + } int8_t retry = 3; while (retry--) { @@ -311,7 +312,7 @@ static int CmdHFCryptoRFDump(const char *Cmd) { // select tag iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + 2); if (packet == NULL) { - PrintAndLogEx(FAILED, "failed to allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } packet->flags = (ISO14B_CONNECT | ISO14B_SELECT_SR); @@ -445,7 +446,7 @@ static int CmdHFCryptoRFELoad(const char *Cmd) { // set up buffer uint8_t *data = calloc(datalen, sizeof(uint8_t)); if (data == NULL) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; } @@ -505,7 +506,7 @@ static int CmdHFCryptoRFESave(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; } diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index 24bd2b35e..04712c91b 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -51,7 +51,7 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile) { uint8_t *fpga_config = calloc(num_infiles * FPGA_CONFIG_SIZE, sizeof(uint8_t)); if (fpga_config == NULL) { - fprintf(stderr, "failed to allocate memory"); + fprintf(stderr, "Failed to allocate memory\n"); return (EXIT_FAILURE); } @@ -94,14 +94,14 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile) { char *outbuf = calloc(outsize_max, sizeof(char)); if (outbuf == NULL) { - fprintf(stderr, "failed to allocate memory"); + fprintf(stderr, "Failed to allocate memory\n"); free(fpga_config); return (EXIT_FAILURE); } char *ring_buffer = calloc(buffer_size, sizeof(char)); if (ring_buffer == NULL) { - fprintf(stderr, "failed to allocate memory"); + fprintf(stderr, "Failed to allocate memory\n"); free(outbuf); free(fpga_config); return (EXIT_FAILURE); @@ -470,7 +470,7 @@ int main(int argc, char **argv) { FILE **outfiles = calloc(num_output_files, sizeof(FILE *)); char **outfile_names = calloc(num_output_files, sizeof(char *)); if (outfiles == NULL || outfile_names == NULL) { - fprintf(stderr, "Error. Cannot allocate memory for output files\n\n"); + fprintf(stderr, "Failed to allocate memory\n\n"); free(outfiles); free(outfile_names); return (EXIT_FAILURE); @@ -533,7 +533,7 @@ int main(int argc, char **argv) { FILE **infiles = calloc(num_input_files, sizeof(FILE *)); char **infile_names = calloc(num_input_files, sizeof(char *)); if (infiles == NULL || infile_names == NULL) { - fprintf(stderr, "Error. Cannot allocate memory for input files\n\n"); + fprintf(stderr, "Failed to allocate memory\n\n"); free(infile_names); free(infiles); return (EXIT_FAILURE); diff --git a/tools/hitag2crack/crack2/ht2crack2search_multi.c b/tools/hitag2crack/crack2/ht2crack2search_multi.c index 0649b5258..27d8aa9dc 100644 --- a/tools/hitag2crack/crack2/ht2crack2search_multi.c +++ b/tools/hitag2crack/crack2/ht2crack2search_multi.c @@ -459,12 +459,12 @@ int main(int argc, char *argv[]) { for (int i = 0; i < thread_count; ++i) { targs *a = calloc(1, rng.len + sizeof(targs)); if (a == NULL) { - printf("Memory allocation failed for thread arguments\n"); + printf("Failed to allocate memory\n"); exit(1); } a->r.data = calloc(1, rng.len); if (a->r.data == NULL) { - printf("Memory allocation failed for rng data\n"); + printf("Failed to allocate memory\n"); free(a); exit(1); } diff --git a/tools/hitag2crack/crack3/ht2crack3.c b/tools/hitag2crack/crack3/ht2crack3.c index 3a185f9a4..91e99c48d 100644 --- a/tools/hitag2crack/crack3/ht2crack3.c +++ b/tools/hitag2crack/crack3/ht2crack3.c @@ -197,8 +197,8 @@ static void *crack(void *d) { // create space for tables Tk = (struct Tklower *)calloc(sizeof(struct Tklower) * 0x40000, sizeof(uint8_t)); - if (!Tk) { - printf("Failed to allocate memory (Tk)\n"); + if (Tk == NULL) { + printf("Failed to allocate memory\n"); exit(1); } diff --git a/tools/hitag2crack/crack4/ht2crack4.c b/tools/hitag2crack/crack4/ht2crack4.c index 70585ed58..db66ab1a5 100644 --- a/tools/hitag2crack/crack4/ht2crack4.c +++ b/tools/hitag2crack/crack4/ht2crack4.c @@ -227,8 +227,8 @@ static uint64_t packstate(uint64_t s) { /* create_guess_table mallocs the tables */ static void create_guess_table(void) { guesses = (struct guess *)calloc(1, sizeof(struct guess) * maxtablesize); - if (!guesses) { - printf("cannot allocate memory for guess table\n"); + if (guesses == NULL) { + printf("Failed to allocate memory\n"); exit(1); } } diff --git a/tools/hitag2crack/crack5opencl/opencl.c b/tools/hitag2crack/crack5opencl/opencl.c index deec49e92..f1a66a6fd 100644 --- a/tools/hitag2crack/crack5opencl/opencl.c +++ b/tools/hitag2crack/crack5opencl/opencl.c @@ -113,7 +113,7 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte // allocate memory to hold info about platforms/devices *cd_ctx = (compute_platform_ctx_t *) calloc(ocl_platform_cnt, sizeof(compute_platform_ctx_t)); if (*cd_ctx == NULL) { - printf("Error: calloc (compute_platform_ctx_t) failed (%d): %s\n", errno, strerror(errno)); + printf("Failed to allocate memory\n"); free(ocl_platforms); return -5; } diff --git a/tools/mfc/card_only/nested_util.c b/tools/mfc/card_only/nested_util.c index f2910de74..b6f0ff32d 100644 --- a/tools/mfc/card_only/nested_util.c +++ b/tools/mfc/card_only/nested_util.c @@ -57,7 +57,7 @@ static countKeys *uniqsort(uint64_t *possibleKeys, uint32_t size) { our_counts = calloc(size, sizeof(countKeys)); if (our_counts == NULL) { - printf("Memory allocation error for our_counts"); + printf("Failed to allocate memory"); exit(EXIT_FAILURE); } @@ -113,7 +113,7 @@ static void *nested_revover(void *args) { // printf("New chunk by %d, sizeof %lu\n", kcount, rp->keyCount * sizeof(uint64_t)); void *tmp = realloc(rp->keys, rp->keyCount * sizeof(uint64_t)); if (tmp == NULL) { - printf("Memory allocation error for pk->possibleKeys"); + printf("Failed to allocate memory\n"); rp->keyCount = 0; is_ok = false; break; @@ -136,7 +136,7 @@ static void *nested_revover(void *args) { rp->keyCount = kcount; void *tmp = (uint64_t *)realloc(rp->keys, rp->keyCount * sizeof(uint64_t)); if (tmp == NULL) { - printf("Memory allocation error for pk->possibleKeys"); + printf("Failed to allocate memory\n"); rp->keyCount = 0; free(rp->keys); } else { @@ -198,14 +198,14 @@ uint64_t *nested(NtpKs1 *pNK, uint32_t sizePNK, uint32_t authuid, uint32_t *keyC free(threads); if (*keyCount == 0) { - printf("Didn't recover any keys.\r\n"); + printf("Didn't recover any keys\r\n"); free(pRPs); return NULL; } keys = calloc((*keyCount) * sizeof(uint64_t), sizeof(uint8_t)); if (keys == NULL) { - printf("Cannot allocate memory to merge keys.\r\n"); + printf("Failed to allocate memory\r\n"); free(pRPs); return NULL; } @@ -231,7 +231,7 @@ uint64_t *nested(NtpKs1 *pNK, uint32_t sizePNK, uint32_t authuid, uint32_t *keyC *keyCount = 0; if (ck == NULL) { - printf("Cannot allocate memory for ck on uniqsort."); + printf("Failed to allocate memory\n"); free(ck); free(pRPs); return NULL; @@ -242,9 +242,10 @@ uint64_t *nested(NtpKs1 *pNK, uint32_t sizePNK, uint32_t authuid, uint32_t *keyC // This key can be found here two or more times if (ck[i].count > 0) { *keyCount += 1; + void *tmp = realloc(keys, sizeof(uint64_t) * (*keyCount)); if (tmp == NULL) { - printf("Cannot allocate memory for keys on merge."); + printf("Failed to allocate memory\n"); free(ck); free(keys); free(pRPs); diff --git a/tools/mfc/card_only/staticnested_0nt.c b/tools/mfc/card_only/staticnested_0nt.c index f0e62c31d..44bfaaf11 100644 --- a/tools/mfc/card_only/staticnested_0nt.c +++ b/tools/mfc/card_only/staticnested_0nt.c @@ -424,6 +424,7 @@ int main(int argc, char *const argv[]) { uint32_t nttest = prng_successor(1, 16); // a first valid nonce pNtData->pNK = (NtpKs1 *)calloc(8192, sizeof(NtpKs1)); // 2**16 filtered with 3 parity bits => 2**13 if (pNtData->pNK == NULL) { + printf("Failed to allocate memory\n"); return 1; } diff --git a/tools/mfc/card_only/staticnested_2nt.c b/tools/mfc/card_only/staticnested_2nt.c index 484c5cdf7..4409d94e2 100644 --- a/tools/mfc/card_only/staticnested_2nt.c +++ b/tools/mfc/card_only/staticnested_2nt.c @@ -201,6 +201,7 @@ int main(int argc, char *const argv[]) { printf("Init...\n"); NtpKs1 *pNK = calloc(2, sizeof(NtpKs1)); if (pNK == NULL) { + printf("Failed to allocate memory\n"); goto error; } diff --git a/tools/mfc/card_reader/mf_nonce_brute.c b/tools/mfc/card_reader/mf_nonce_brute.c index 6504b29ab..27968620f 100644 --- a/tools/mfc/card_reader/mf_nonce_brute.c +++ b/tools/mfc/card_reader/mf_nonce_brute.c @@ -738,7 +738,7 @@ int main(int argc, const char *argv[]) { printf("Testing default keys using NESTED authentication...\n"); struct thread_key_args *def = calloc(1, sizeof(struct thread_key_args)); if (def == NULL) { - fprintf(stderr, "Memory allocation failed\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } def->thread = 0; @@ -763,7 +763,7 @@ int main(int argc, const char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_args *a = calloc(1, sizeof(struct thread_args)); if (a == NULL) { - fprintf(stderr, "Memory allocation failed\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } a->xored = xored; @@ -789,7 +789,7 @@ int main(int argc, const char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_args *a = calloc(1, sizeof(struct thread_args)); if (a == NULL) { - fprintf(stderr, "Memory allocation failed\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } a->xored = xored; @@ -836,7 +836,7 @@ int main(int argc, const char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_key_args *b = calloc(1, sizeof(struct thread_key_args)); if (b == NULL) { - fprintf(stderr, "Memory allocation failed\n"); + fprintf(stderr, "Failed to allocaet memory\n"); exit(EXIT_FAILURE); } b->thread = i; diff --git a/tools/mfc/card_reader/mf_trace_brute.c b/tools/mfc/card_reader/mf_trace_brute.c index 3eff1bde6..974b78274 100644 --- a/tools/mfc/card_reader/mf_trace_brute.c +++ b/tools/mfc/card_reader/mf_trace_brute.c @@ -291,7 +291,7 @@ int main(int argc, const char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_args *a = calloc(1, sizeof(struct thread_args)); if (a == NULL) { - fprintf(stderr, "Failed to allocate memory for thread arguments\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } a->thread = i; diff --git a/tools/mfd_aes_brute/mfd_aes_brute.c b/tools/mfd_aes_brute/mfd_aes_brute.c index 839c4bf61..029e7ba8f 100644 --- a/tools/mfd_aes_brute/mfd_aes_brute.c +++ b/tools/mfd_aes_brute/mfd_aes_brute.c @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_args *a = calloc(1, sizeof(struct thread_args)); if (a == NULL) { - fprintf(stderr, "Failed to allocate memory for thread arguments\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } a->thread = i; diff --git a/tools/mfd_aes_brute/mfd_multi_brute.c b/tools/mfd_aes_brute/mfd_multi_brute.c index 9bd61c563..cce9e730f 100644 --- a/tools/mfd_aes_brute/mfd_multi_brute.c +++ b/tools/mfd_aes_brute/mfd_multi_brute.c @@ -472,7 +472,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < thread_count; ++i) { struct thread_args *a = calloc(1, sizeof(struct thread_args)); if (a == NULL) { - fprintf(stderr, "Failed to allocate memory for thread arguments\n"); + fprintf(stderr, "Failed to allocate memory\n"); exit(EXIT_FAILURE); } a->thread = i;