cppcheck nullPointerOutOfMemory

This commit is contained in:
Philippe Teuwen 2025-03-24 23:46:43 +01:00
commit ad84875afd
44 changed files with 314 additions and 5 deletions

View file

@ -46,6 +46,11 @@ int flashmem_spiffs_load(const char *destfn, const uint8_t *data, size_t datalen
uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining); uint32_t bytes_in_packet = MIN(FLASH_MEM_BLOCK_SIZE, bytes_remaining);
flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet); flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet);
if (payload == NULL) {
PrintAndLogEx(ERR, "error, cannot allocate memory ");
ret_val = PM3_EMALLOC;
goto out;
}
payload->append = (bytes_sent > 0); payload->append = (bytes_sent > 0);

View file

@ -901,6 +901,10 @@ static int CmdLegicDump(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Reading tag memory." NOLF); PrintAndLogEx(SUCCESS, "Reading tag memory." NOLF);
legic_packet_t *payload = calloc(1, sizeof(legic_packet_t)); legic_packet_t *payload = calloc(1, sizeof(legic_packet_t));
if (payload == NULL) {
PrintAndLogEx(WARNING, "Cannot allocate memory");
return PM3_EMALLOC;
}
payload->offset = 0; payload->offset = 0;
payload->iv = 0x55; payload->iv = 0x55;
payload->len = dumplen; payload->len = dumplen;

View file

@ -542,6 +542,10 @@ static void topaz_print_control_TLVs(uint8_t *memory) {
if (old == NULL) { if (old == NULL) {
new = topaz_tag.dynamic_lock_areas = (dynamic_lock_area_t *) calloc(sizeof(dynamic_lock_area_t), sizeof(uint8_t)); 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");
return;
}
} else { } else {
while (old->next != NULL) { while (old->next != NULL) {
old = old->next; old = old->next;

View file

@ -858,6 +858,10 @@ static int CmdFdxBSim(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _YELLOW_("%04u-%"PRIu64), country_code, national_code); PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _YELLOW_("%04u-%"PRIu64), country_code, national_code);
uint8_t *bs = calloc(128, sizeof(uint8_t)); uint8_t *bs = calloc(128, sizeof(uint8_t));
if (bs == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed.");
return PM3_EMALLOC;
}
if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bs) != PM3_SUCCESS) { if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bs) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Error with tag bitstream generation."); PrintAndLogEx(ERR, "Error with tag bitstream generation.");
free(bs); free(bs);
@ -866,6 +870,11 @@ static int CmdFdxBSim(const char *Cmd) {
// 32, no STT, BIPHASE INVERTED == diphase // 32, no STT, BIPHASE INVERTED == diphase
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + 128); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + 128);
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed.");
free(bs);
return PM3_EMALLOC;
}
payload->encoding = 2; payload->encoding = 2;
payload->invert = 1; payload->invert = 1;
payload->separator = 0; payload->separator = 0;

View file

@ -363,6 +363,10 @@ static int CmdGallagherSim(const char *Cmd) {
bytes_to_bytebits(raw, sizeof(raw), bs); bytes_to_bytebits(raw, sizeof(raw), bs);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 0; payload->separator = 0;

View file

@ -387,6 +387,10 @@ static int CmdGuardSim(const char *Cmd) {
// Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase) // Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase)
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed.");
return PM3_EMALLOC;
}
payload->encoding = 2; payload->encoding = 2;
payload->invert = 0; payload->invert = 0;
payload->separator = 0; payload->separator = 0;

View file

@ -1678,7 +1678,12 @@ static int CmdLFHitagEload(const char *Cmd) {
// check dump len.. // check dump len..
if (bytes_read == HITAG2_MAX_BYTE_SIZE || bytes_read == 4 * 64) { if (bytes_read == HITAG2_MAX_BYTE_SIZE || bytes_read == 4 * 64) {
lf_hitag_t *payload = calloc(1, sizeof(lf_hitag_t) + bytes_read); lf_hitag_t *payload = calloc(1, sizeof(lf_hitag_t) + bytes_read);
if (payload == NULL) {
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
free(dump);
return PM3_EMALLOC;
}
if (use_ht1) if (use_ht1)
payload->type = 1; payload->type = 1;

View file

@ -175,6 +175,10 @@ static int sendTry(uint8_t fc, uint16_t cn, uint32_t delay, bool fmt4041x, bool
// indala PSK, clock 32, carrier 0 // indala PSK, clock 32, carrier 0
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->carrier = 2; payload->carrier = 2;
payload->invert = 0; payload->invert = 0;
payload->clock = 32; payload->clock = 32;
@ -756,6 +760,10 @@ static int CmdIndalaSim(const char *Cmd) {
// indala PSK, clock 32, carrier 0 // indala PSK, clock 32, carrier 0
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->carrier = 2; payload->carrier = 2;
payload->invert = 0; payload->invert = 0;
payload->clock = 32; payload->clock = 32;

View file

@ -251,6 +251,10 @@ static int CmdIOProxSim(const char *Cmd) {
// arg2 --- Invert and clk setting // arg2 --- Invert and clk setting
// size --- 64 bits == 8 bytes // size --- 64 bits == 8 bytes
lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
payload->fchigh = 10; payload->fchigh = 10;
payload->fclow = 8; payload->fclow = 8;
payload->separator = 1; payload->separator = 1;

View file

@ -284,6 +284,11 @@ static int CmdJablotronSim(const char *Cmd) {
getJablotronBits(fullcode, bs); getJablotronBits(fullcode, bs);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + JABLOTRON_ARR_LEN); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + JABLOTRON_ARR_LEN);
if (payload == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
free(bs);
return PM3_EMALLOC;
}
payload->encoding = 2; payload->encoding = 2;
payload->invert = 1; payload->invert = 1;
payload->separator = 0; payload->separator = 0;

View file

@ -346,6 +346,10 @@ static int CmdKeriSim(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64), internalid); PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64), internalid);
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->carrier = 2; payload->carrier = 2;
payload->invert = 0; payload->invert = 0;
payload->clock = 32; payload->clock = 32;

View file

@ -539,6 +539,10 @@ static int CmdLFNedapSim(const char *Cmd) {
// NEDAP, Biphase = 2, clock 64, inverted, (DIPhase == inverted BIphase) // NEDAP, Biphase = 2, clock 64, inverted, (DIPhase == inverted BIphase)
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + g_DemodBufferLen); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + g_DemodBufferLen);
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 2; payload->encoding = 2;
payload->invert = 1; payload->invert = 1;
payload->separator = 0; payload->separator = 0;

View file

@ -423,7 +423,17 @@ static int CmdNexWatchClone(const char *Cmd) {
blocks[0] = 0x00042080; blocks[0] = 0x00042080;
uint8_t *res_shifted = calloc(96, sizeof(uint8_t)); uint8_t *res_shifted = calloc(96, sizeof(uint8_t));
if (res_shifted == NULL) {
PrintAndLogEx(FAILED, "Memory allocation failed for res_shifted");
return PM3_EMALLOC;
}
uint8_t *res = calloc(96, sizeof(uint8_t)); uint8_t *res = calloc(96, sizeof(uint8_t));
if (res == NULL) {
PrintAndLogEx(FAILED, "Memory allocation failed for res");
free(res_shifted);
return PM3_EMALLOC;
}
bytes_to_bytebits(raw, 12, res); bytes_to_bytebits(raw, 12, res);
psk1TOpsk2(res, 96); psk1TOpsk2(res, 96);
@ -546,6 +556,10 @@ static int CmdNexWatchSim(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Simulating NexWatch - raw " _YELLOW_("%s"), sprint_hex_inrow(raw, sizeof(raw))); PrintAndLogEx(SUCCESS, "Simulating NexWatch - raw " _YELLOW_("%s"), sprint_hex_inrow(raw, sizeof(raw)));
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs)); lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "Memory allocation failed for payload");
return PM3_EMALLOC;
}
payload->carrier = 2; payload->carrier = 2;
payload->invert = 0; payload->invert = 0;
payload->clock = 32; payload->clock = 32;

View file

@ -261,6 +261,10 @@ static int CmdNoralsySim(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Simulating Noralsy - CardId: " _YELLOW_("%u") " year " _YELLOW_("%u"), id, year); PrintAndLogEx(SUCCESS, "Simulating Noralsy - CardId: " _YELLOW_("%u") " year " _YELLOW_("%u"), id, year);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed.");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 1; payload->separator = 1;

View file

@ -368,6 +368,10 @@ static int CmdPacSim(const char *Cmd) {
// NRZ sim. // NRZ sim.
lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs)); lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->invert = 0; payload->invert = 0;
payload->separator = 0; payload->separator = 0;
payload->clock = 32; payload->clock = 32;

View file

@ -446,6 +446,10 @@ static int CmdParadoxSim(const char *Cmd) {
uint8_t clk = 50, high = 10, low = 8; uint8_t clk = 50, high = 10, low = 8;
lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
payload->fchigh = high; payload->fchigh = high;
payload->fclow = low; payload->fclow = low;
payload->separator = 0; payload->separator = 0;

View file

@ -333,6 +333,10 @@ static int CmdPrescoSim(const char *Cmd) {
getPrescoBits(fullcode, bs); getPrescoBits(fullcode, bs);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 1; payload->separator = 1;

View file

@ -428,6 +428,10 @@ static int CmdPyramidSim(const char *Cmd) {
// Pyramid uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0 // Pyramid uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0
lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs)); lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
payload->fchigh = 10; payload->fchigh = 10;
payload->fclow = 8; payload->fclow = 8;
payload->separator = 0; payload->separator = 0;

View file

@ -270,6 +270,10 @@ static int CmdSecurakeySim(const char *Cmd) {
bytes_to_bytebits(raw, sizeof(raw), bs); bytes_to_bytebits(raw, sizeof(raw), bs);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 0; payload->separator = 0;

View file

@ -345,6 +345,14 @@ static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, u
char *r2 = (char *)calloc(r_count, sizeof(uint8_t)); char *r2 = (char *)calloc(r_count, sizeof(uint8_t));
char *r3 = (char *)calloc(r_count, sizeof(uint8_t)); char *r3 = (char *)calloc(r_count, sizeof(uint8_t));
if (r0 == NULL || r1 == NULL || r2 == NULL || r3 == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
free(r0);
free(r1);
free(r2);
free(r3);
return;
}
snprintf(r0, r_len, "downlink - fixed bit length %s", (dl_mode_def == 0) ? "(detected def)" : ""); snprintf(r0, r_len, "downlink - fixed bit length %s", (dl_mode_def == 0) ? "(detected def)" : "");
snprintf(r1, r_len, "downlink - long leading reference %s", (dl_mode_def == 1) ? "(detected def)" : ""); snprintf(r1, r_len, "downlink - long leading reference %s", (dl_mode_def == 1) ? "(detected def)" : "");
snprintf(r2, r_len, "downlink - leading zero %s", (dl_mode_def == 2) ? "(detected def)" : ""); snprintf(r2, r_len, "downlink - leading zero %s", (dl_mode_def == 2) ? "(detected def)" : "");
@ -358,6 +366,14 @@ static void arg_add_t55xx_downloadlink(void *at[], uint8_t *idx, uint8_t show, u
if (show == T55XX_DLMODE_ALL) { if (show == T55XX_DLMODE_ALL) {
char *r4 = (char *)calloc(r_count, sizeof(uint8_t)); char *r4 = (char *)calloc(r_count, sizeof(uint8_t));
if (r4 == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
free(r0);
free(r1);
free(r2);
free(r3);
return;
}
snprintf(r4, r_len, "try all downlink modes %s", (dl_mode_def == 4) ? "(def)" : ""); snprintf(r4, r_len, "try all downlink modes %s", (dl_mode_def == 4) ? "(def)" : "");
at[n++] = arg_lit0(NULL, "all", r4); at[n++] = arg_lit0(NULL, "all", r4);
} }

View file

@ -218,6 +218,10 @@ static int CmdVikingSim(const char *Cmd) {
num_to_bytebits(rawID, sizeof(bs), bs); num_to_bytebits(rawID, sizeof(bs), bs);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 0; payload->separator = 0;

View file

@ -276,6 +276,10 @@ static int CmdVisa2kSim(const char *Cmd) {
num_to_bytebits(blocks[i], 32, bs + i * 32); num_to_bytebits(blocks[i], 32, bs + i * 32);
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->encoding = 1; payload->encoding = 1;
payload->invert = 0; payload->invert = 0;
payload->separator = 1; payload->separator = 1;

View file

@ -59,6 +59,12 @@ static void AppendDate(char *s, size_t slen, const char *fmt) {
#else #else
ct = gmtime_r(&now, &tm_buf); ct = gmtime_r(&now, &tm_buf);
#endif #endif
if (ct == NULL) {
PrintAndLogEx(ERR, "gmtime failed");
return;
}
// If no format is specified, use ISO8601
if (fmt == NULL) if (fmt == NULL)
strftime(s, slen, "%Y-%m-%dT%H:%M:%SZ", ct); // ISO8601 strftime(s, slen, "%Y-%m-%dT%H:%M:%SZ", ct); // ISO8601
else else

View file

@ -364,6 +364,10 @@ static int smart_responseEx(uint8_t *out, int maxoutlen, bool verbose) {
uint8_t cmd_getresp[] = {0x00, ISO7816_GET_RESPONSE, 0x00, 0x00, len}; 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)); smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(cmd_getresp));
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
goto out;
}
payload->flags = SC_RAW | SC_LOG; payload->flags = SC_RAW | SC_LOG;
payload->len = sizeof(cmd_getresp); payload->len = sizeof(cmd_getresp);
payload->wait_delay = 0; payload->wait_delay = 0;
@ -903,8 +907,10 @@ static int CmdSmartList(const char *Cmd) {
static void smart_brute_prim(void) { static void smart_brute_prim(void) {
uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
if (!buf) if (buf == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return; return;
}
uint8_t get_card_data[] = { uint8_t get_card_data[] = {
0x80, 0xCA, 0x9F, 0x13, 0x00, 0x80, 0xCA, 0x9F, 0x13, 0x00,
@ -918,6 +924,11 @@ static void smart_brute_prim(void) {
for (int i = 0; i < ARRAYLEN(get_card_data); i += 5) { for (int i = 0; i < ARRAYLEN(get_card_data); i += 5) {
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + 5); smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + 5);
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
free(buf);
return;
}
payload->flags = SC_RAW_T0; payload->flags = SC_RAW_T0;
payload->len = 5; payload->len = 5;
payload->wait_delay = 0; payload->wait_delay = 0;
@ -938,8 +949,10 @@ static void smart_brute_prim(void) {
static int smart_brute_sfi(bool decodeTLV) { static int smart_brute_sfi(bool decodeTLV) {
uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
if (buf == NULL) if (buf == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return 1; return 1;
}
int len; int len;
// READ RECORD // READ RECORD
@ -962,6 +975,11 @@ static int smart_brute_sfi(bool decodeTLV) {
READ_RECORD[3] = (sfi << 3) | 4; READ_RECORD[3] = (sfi << 3) | 4;
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(READ_RECORD)); smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(READ_RECORD));
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
free(buf);
return 1;
}
payload->flags = SC_RAW_T0; payload->flags = SC_RAW_T0;
payload->len = sizeof(READ_RECORD); payload->len = sizeof(READ_RECORD);
payload->wait_delay = 0; payload->wait_delay = 0;
@ -1007,13 +1025,20 @@ static int smart_brute_sfi(bool decodeTLV) {
static void smart_brute_options(bool decodeTLV) { static void smart_brute_options(bool decodeTLV) {
uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
if (!buf) if (buf == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return; return;
}
// Get processing options command // Get processing options command
uint8_t GET_PROCESSING_OPTIONS[] = {0x80, 0xA8, 0x00, 0x00, 0x02, 0x83, 0x00, 0x00}; uint8_t GET_PROCESSING_OPTIONS[] = {0x80, 0xA8, 0x00, 0x00, 0x02, 0x83, 0x00, 0x00};
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(GET_PROCESSING_OPTIONS)); 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");
free(buf);
return;
}
payload->flags = SC_RAW_T0; payload->flags = SC_RAW_T0;
payload->len = sizeof(GET_PROCESSING_OPTIONS); payload->len = sizeof(GET_PROCESSING_OPTIONS);
memcpy(payload->data, GET_PROCESSING_OPTIONS, sizeof(GET_PROCESSING_OPTIONS)); memcpy(payload->data, GET_PROCESSING_OPTIONS, sizeof(GET_PROCESSING_OPTIONS));
@ -1111,6 +1136,12 @@ static int CmdSmartBruteforceSFI(const char *Cmd) {
size_t aidlen = strlen(aid); size_t aidlen = strlen(aid);
caid = calloc(8 + 2 + aidlen + 1, sizeof(uint8_t)); caid = calloc(8 + 2 + aidlen + 1, sizeof(uint8_t));
if (caid == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
json_decref(root);
free(buf);
return PM3_EMALLOC;
}
snprintf(caid, 8 + 2 + aidlen + 1, SELECT, aidlen >> 1, aid); snprintf(caid, 8 + 2 + aidlen + 1, SELECT, aidlen >> 1, aid);
int hexlen = 0; int hexlen = 0;
@ -1120,6 +1151,12 @@ static int CmdSmartBruteforceSFI(const char *Cmd) {
continue; continue;
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + hexlen); smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + hexlen);
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
json_decref(root);
free(buf);
return PM3_EMALLOC;
}
payload->flags = SC_RAW_T0; payload->flags = SC_RAW_T0;
payload->len = hexlen; payload->len = hexlen;
payload->wait_delay = 0; payload->wait_delay = 0;
@ -1470,6 +1507,10 @@ int ExchangeAPDUSC(bool verbose, uint8_t *datain, int datainlen, bool activateCa
*dataoutlen = 0; *dataoutlen = 0;
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + datainlen); smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + datainlen);
if (payload == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
payload->flags = (SC_RAW_T0 | SC_LOG); payload->flags = (SC_RAW_T0 | SC_LOG);
if (activateCard) { if (activateCard) {
payload->flags |= (SC_SELECT | SC_CONNECT); payload->flags |= (SC_SELECT | SC_CONNECT);

View file

@ -770,6 +770,12 @@ bool OpenProxmarkSilent(pm3_device_t **dev, const char *port, uint32_t speed) {
fflush(stdout); fflush(stdout);
if (*dev == NULL) { if (*dev == NULL) {
*dev = calloc(sizeof(pm3_device_t), sizeof(uint8_t)); *dev = calloc(sizeof(pm3_device_t), sizeof(uint8_t));
if (*dev == NULL) {
PrintAndLogEx(ERR, "Failed to allocate memory for pm3_device_t");
uart_close(sp);
sp = NULL;
return false;
}
} }
(*dev)->g_conn = &g_conn; // TODO g_conn shouldn't be global (*dev)->g_conn = &g_conn; // TODO g_conn shouldn't be global
return true; return true;
@ -827,7 +833,13 @@ bool OpenProxmark(pm3_device_t **dev, const char *port, bool wait_for_port, int
fflush(stdout); fflush(stdout);
if (*dev == NULL) { if (*dev == NULL) {
*dev = calloc(sizeof(pm3_device_t), sizeof(uint8_t)); *dev = calloc(1, sizeof(pm3_device_t));
if (*dev == NULL) {
PrintAndLogEx(ERR, "Failed to allocate memory for pm3_device_t");
uart_close(sp);
sp = NULL;
return false;
}
} }
(*dev)->g_conn = &g_conn; // TODO g_conn shouldn't be global (*dev)->g_conn = &g_conn; // TODO g_conn shouldn't be global
return true; return true;

View file

@ -64,6 +64,9 @@ static struct crypto_hash *crypto_hash_polarssl_open(enum crypto_algo_hash hash)
return NULL; return NULL;
struct crypto_hash_polarssl *ch = calloc(1, sizeof(*ch)); struct crypto_hash_polarssl *ch = calloc(1, sizeof(*ch));
if (ch == NULL) {
return NULL;
}
mbedtls_sha1_starts(&(ch->ctx)); mbedtls_sha1_starts(&(ch->ctx));
@ -82,6 +85,9 @@ struct crypto_pk_polarssl {
static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl) { static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl) {
struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp));
if (cp == NULL) {
return NULL;
}
memset(cp, 0x00, sizeof(*cp)); memset(cp, 0x00, sizeof(*cp));
char *mod = va_arg(vl, char *); // N char *mod = va_arg(vl, char *); // N
@ -107,6 +113,9 @@ 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) { static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl) {
struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp));
if (cp == NULL) {
return NULL;
}
memset(cp, 0x00, sizeof(*cp)); memset(cp, 0x00, sizeof(*cp));
char *mod = va_arg(vl, char *); char *mod = va_arg(vl, char *);
int modlen = va_arg(vl, size_t); int modlen = va_arg(vl, size_t);
@ -167,6 +176,9 @@ static int myrand(void *rng_state, unsigned char *output, size_t len) {
static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl) { static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl) {
struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp)); struct crypto_pk_polarssl *cp = calloc(1, sizeof(*cp));
if (cp == NULL) {
return NULL;
}
memset(cp, 0x00, sizeof(*cp)); memset(cp, 0x00, sizeof(*cp));
int transient = va_arg(vl, int); int transient = va_arg(vl, int);
@ -251,6 +263,10 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
case 0: case 0:
*plen = mbedtls_mpi_size(&cp->ctx.N); *plen = mbedtls_mpi_size(&cp->ctx.N);
result = calloc(1, *plen); result = calloc(1, *plen);
if (result == NULL) {
PrintAndLogEx(WARNING, "Error allocating memory for parameter");
return 0;
}
memset(result, 0x00, *plen); memset(result, 0x00, *plen);
res = mbedtls_mpi_write_binary(&cp->ctx.N, result, *plen); res = mbedtls_mpi_write_binary(&cp->ctx.N, result, *plen);
if (res < 0) { if (res < 0) {
@ -263,6 +279,10 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
case 1: case 1:
*plen = mbedtls_mpi_size(&cp->ctx.E); *plen = mbedtls_mpi_size(&cp->ctx.E);
result = calloc(1, *plen); result = calloc(1, *plen);
if (result == NULL) {
PrintAndLogEx(WARNING, "Error allocating memory for parameter");
return 0;
}
memset(result, 0x00, *plen); memset(result, 0x00, *plen);
res = mbedtls_mpi_write_binary(&cp->ctx.E, result, *plen); res = mbedtls_mpi_write_binary(&cp->ctx.E, result, *plen);
if (res < 0) { if (res < 0) {

View file

@ -55,6 +55,8 @@ struct tlv *dol_process(const struct tlv *tlv, const struct tlvdb *tlvdb, tlv_ta
size_t res_len; size_t res_len;
if (!tlv || !(res_len = dol_calculate_len(tlv, 0))) { if (!tlv || !(res_len = dol_calculate_len(tlv, 0))) {
struct tlv *res_tlv = calloc(1, sizeof(*res_tlv)); struct tlv *res_tlv = calloc(1, sizeof(*res_tlv));
if (!res_tlv)
return NULL;
res_tlv->tag = tag; res_tlv->tag = tag;
res_tlv->len = 0; res_tlv->len = 0;

View file

@ -169,6 +169,9 @@ 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 *emv_pk_parse_pk(char *buf, size_t buflen) {
struct emv_pk *r = calloc(1, sizeof(*r)); struct emv_pk *r = calloc(1, sizeof(*r));
if (r == NULL) {
return NULL;
}
ssize_t l; ssize_t l;
char temp[10]; char temp[10];

View file

@ -346,6 +346,10 @@ unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
if (len) { if (len) {
*sdatl_len = len; *sdatl_len = len;
unsigned char *value = calloc(1, len); unsigned char *value = calloc(1, len);
if (value == NULL) {
PrintAndLogEx(WARNING, "ERROR: Memory allocation failed");
return NULL;
}
memcpy(value, buf, len); memcpy(value, buf, len);
return value; return value;
} }

View file

@ -245,6 +245,10 @@ static int cda_test_raw(bool verbose) {
size_t iccpk_pk_len = iccpk_data[19]; size_t iccpk_pk_len = iccpk_data[19];
unsigned char *iccpk_pk = calloc(1, iccpk_pk_len); unsigned char *iccpk_pk = calloc(1, iccpk_pk_len);
if (!iccpk_pk) {
free(iccpk_data);
return 1;
}
memcpy(iccpk_pk, iccpk_data + 21, /*iccpk_data_len - 36*/iccpk_pk_len); memcpy(iccpk_pk, iccpk_data + 21, /*iccpk_data_len - 36*/iccpk_pk_len);
/*memcpy(iccpk_pk + iccpk_data_len - 36, icc_rem, sizeof(icc_rem));*/ /*memcpy(iccpk_pk + iccpk_data_len - 36, icc_rem, sizeof(icc_rem));*/

View file

@ -233,6 +233,10 @@ static int dda_test_raw(bool verbose) {
size_t iccpk_pk_len = iccpk_data[19]; size_t iccpk_pk_len = iccpk_data[19];
unsigned char *iccpk_pk = calloc(1, iccpk_pk_len); unsigned char *iccpk_pk = calloc(1, iccpk_pk_len);
if (!iccpk_pk) {
free(iccpk_data);
return 1;
}
memcpy(iccpk_pk, iccpk_data + 21, /*iccpk_data_len - 36*/iccpk_pk_len); memcpy(iccpk_pk, iccpk_data + 21, /*iccpk_data_len - 36*/iccpk_pk_len);
/*memcpy(iccpk_pk + iccpk_data_len - 36, icc_rem, sizeof(icc_rem));*/ /*memcpy(iccpk_pk + iccpk_data_len - 36, icc_rem, sizeof(icc_rem));*/

View file

@ -471,6 +471,10 @@ bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge) {
void add_temporary_marker(uint32_t position, const char *label) { void add_temporary_marker(uint32_t position, const char *label) {
if (g_TempMarkerSize == 0) { //Initialize the marker array if (g_TempMarkerSize == 0) { //Initialize the marker array
g_TempMarkers = (marker_t *)calloc(1, sizeof(marker_t)); 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!");
return;
}
} else { //add more space to the marker array using realloc() } else { //add more space to the marker array using realloc()
marker_t *temp = (marker_t *)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t))); marker_t *temp = (marker_t *)realloc(g_TempMarkers, ((g_TempMarkerSize + 1) * sizeof(marker_t)));
@ -487,6 +491,10 @@ void add_temporary_marker(uint32_t position, const char *label) {
g_TempMarkers[g_TempMarkerSize].pos = position; g_TempMarkers[g_TempMarkerSize].pos = position;
char *markerLabel = (char *)calloc(1, strlen(label) + 1); char *markerLabel = (char *)calloc(1, strlen(label) + 1);
if (markerLabel == NULL) {
PrintAndLogEx(FAILED, "Unable to allocate memory for marker label!");
return;
}
strcpy(markerLabel, label); strcpy(markerLabel, label);
if (strlen(markerLabel) > 30) { if (strlen(markerLabel) > 30) {
@ -512,6 +520,11 @@ void remove_temporary_markers(void) {
buffer_savestate_t save_buffer32(uint32_t *src, size_t length) { buffer_savestate_t save_buffer32(uint32_t *src, size_t length) {
//calloc the memory needed //calloc the memory needed
uint32_t *savedBuffer = (uint32_t *)calloc(length, sizeof(uint32_t)); uint32_t *savedBuffer = (uint32_t *)calloc(length, sizeof(uint32_t));
if (savedBuffer == NULL) {
PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!");
buffer_savestate_t bst = {0};
return bst;
}
//Make a copy of the source buffer //Make a copy of the source buffer
memcpy(savedBuffer, src, (length * sizeof(uint32_t))); memcpy(savedBuffer, src, (length * sizeof(uint32_t)));
@ -529,6 +542,11 @@ buffer_savestate_t save_buffer32(uint32_t *src, size_t length) {
buffer_savestate_t save_bufferS32(int32_t *src, size_t length) { buffer_savestate_t save_bufferS32(int32_t *src, size_t length) {
//calloc the memory needed //calloc the memory needed
uint32_t *savedBuffer = (uint32_t *)calloc(length, (sizeof(uint32_t))); uint32_t *savedBuffer = (uint32_t *)calloc(length, (sizeof(uint32_t)));
if (savedBuffer == NULL) {
PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!");
buffer_savestate_t bst = {0};
return bst;
}
//Make a copy of the source buffer //Make a copy of the source buffer
memcpy(savedBuffer, src, (length * sizeof(uint32_t))); memcpy(savedBuffer, src, (length * sizeof(uint32_t)));
@ -558,6 +576,11 @@ buffer_savestate_t save_buffer8(uint8_t *src, size_t length) {
// calloc the memory needed // calloc the memory needed
uint32_t *savedBuffer = (uint32_t *)calloc(buffSize, sizeof(uint32_t)); uint32_t *savedBuffer = (uint32_t *)calloc(buffSize, sizeof(uint32_t));
if (savedBuffer == NULL) {
PrintAndLogEx(FAILED, "Unable to allocate memory for the buffer!");
buffer_savestate_t bst = {0};
return bst;
}
size_t index = 0; size_t index = 0;
// Pack the source array into the backing array // Pack the source array into the backing array

View file

@ -262,6 +262,10 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
uint8_t *address_data; uint8_t *address_data;
uint8_t div_key[8]; uint8_t div_key[8];
address_data = (uint8_t *) calloc(address_data_size, sizeof(uint8_t)); address_data = (uint8_t *) calloc(address_data_size, sizeof(uint8_t));
if (address_data == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed\n");
return;
}
memcpy(address_data, address_data_p, address_data_size); memcpy(address_data, address_data_p, address_data_size);
memcpy(div_key, div_key_p, 8); memcpy(div_key, div_key_p, 8);

View file

@ -131,6 +131,10 @@ void printarr(const char *name, uint8_t *arr, int len) {
int cx, i; int cx, i;
size_t outsize = 40 + strlen(name) + len * 5; size_t outsize = 40 + strlen(name) + len * 5;
char *output = calloc(outsize, sizeof(char)); char *output = calloc(outsize, sizeof(char));
if (output == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return;
}
cx = snprintf(output, outsize, "uint8_t %s[] = {", name); cx = snprintf(output, outsize, "uint8_t %s[] = {", name);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (cx < outsize) if (cx < outsize)

View file

@ -366,6 +366,10 @@ static void *bf_thread(void *thread_arg) {
if (memcmp(calculated_MAC, mac, 4) == 0) { if (memcmp(calculated_MAC, mac, 4) == 0) {
loclass_thread_ret_t *r = (loclass_thread_ret_t *)calloc(sizeof(loclass_thread_ret_t), sizeof(uint8_t)); 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");
pthread_exit(NULL);
}
for (uint8_t i = 0 ; i < numbytes_to_recover; i++) { for (uint8_t i = 0 ; i < numbytes_to_recover; i++) {
r->values[i] = keytable[bytes_to_recover[i]] & 0xFF; r->values[i] = keytable[bytes_to_recover[i]] & 0xFF;

View file

@ -550,6 +550,10 @@ void invert_hash0(uint8_t k[8]) {
// Initialize an array of pointers to uint64_t (start with one value, initialized to 0) // 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 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");
return;
}
hydra_heads[0] = 0; // Initialize first value to 0 hydra_heads[0] = 0; // Initialize first value to 0
int heads_count = 1; // Track number of forks int heads_count = 1; // Track number of forks

View file

@ -1077,6 +1077,10 @@ int mf_eml_set_mem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtW
size_t paylen = sizeof(struct p) + size; size_t paylen = sizeof(struct p) + size;
struct p *payload = calloc(1, paylen); struct p *payload = calloc(1, paylen);
if (payload == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
payload->blockno = blockNum; payload->blockno = blockNum;
payload->blockcnt = blocksCount; payload->blockcnt = blocksCount;

View file

@ -1080,6 +1080,10 @@ static int ndefDecodePayload(NDEFHeader_t *ndef, bool verbose) {
} }
char *begin = calloc(ndef->TypeLen + 1, sizeof(char)); char *begin = calloc(ndef->TypeLen + 1, sizeof(char));
if (begin == NULL) {
PrintAndLogEx(ERR, "Memory allocation failed");
return PM3_EMALLOC;
}
memcpy(begin, ndef->Type, ndef->TypeLen); memcpy(begin, ndef->Type, ndef->TypeLen);
str_lower(begin); str_lower(begin);

View file

@ -1385,6 +1385,10 @@ static int setLuaPath(lua_State *L, const char *path) {
const char *cur_path = lua_tostring(L, -1); // grab path string from top of stack const char *cur_path = lua_tostring(L, -1); // grab path string from top of stack
int requiredLength = strlen(cur_path) + strlen(path) + 10; //A few bytes too many, whatever we can afford it int requiredLength = strlen(cur_path) + strlen(path) + 10; //A few bytes too many, whatever we can afford it
char *buf = calloc(requiredLength, sizeof(char)); char *buf = calloc(requiredLength, sizeof(char));
if (buf == NULL) {
lua_pop(L, 1); // get rid of package table from top of stack
return returnToLuaWithError(L, "Failed to allocate memory");
}
snprintf(buf, requiredLength, "%s;%s", cur_path, path); snprintf(buf, requiredLength, "%s;%s", cur_path, path);
lua_pop(L, 1); // get rid of the string on the stack we just pushed on line 5 lua_pop(L, 1); // get rid of the string on the stack we just pushed on line 5
lua_pushstring(L, buf); // push the new one lua_pushstring(L, buf); // push the new one

View file

@ -469,6 +469,12 @@ int main(int argc, char **argv) {
uint8_t num_output_files = argc - 3; uint8_t num_output_files = argc - 3;
FILE **outfiles = calloc(num_output_files, sizeof(FILE *)); FILE **outfiles = calloc(num_output_files, sizeof(FILE *));
char **outfile_names = calloc(num_output_files, sizeof(char *)); 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");
free(outfiles);
free(outfile_names);
return (EXIT_FAILURE);
}
for (uint8_t i = 0; i < num_output_files; i++) { for (uint8_t i = 0; i < num_output_files; i++) {
outfile_names[i] = argv[i + 3]; outfile_names[i] = argv[i + 3];
outfiles[i] = fopen(outfile_names[i], "wb"); outfiles[i] = fopen(outfile_names[i], "wb");
@ -526,6 +532,12 @@ int main(int argc, char **argv) {
FILE **infiles = calloc(num_input_files, sizeof(FILE *)); FILE **infiles = calloc(num_input_files, sizeof(FILE *));
char **infile_names = calloc(num_input_files, sizeof(char *)); 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");
free(infile_names);
free(infiles);
return (EXIT_FAILURE);
}
for (uint8_t i = 0; i < num_input_files; i++) { for (uint8_t i = 0; i < num_input_files; i++) {
infile_names[i] = argv[i + (generate_version_file ? 2 : 1)]; infile_names[i] = argv[i + (generate_version_file ? 2 : 1)];
infiles[i] = fopen(infile_names[i], "rb"); infiles[i] = fopen(infile_names[i], "rb");

View file

@ -737,6 +737,10 @@ int main(int argc, const char *argv[]) {
printf("----------- " _CYAN_("Phase 1 pre-processing") " ------------------------\n"); printf("----------- " _CYAN_("Phase 1 pre-processing") " ------------------------\n");
printf("Testing default keys using NESTED authentication...\n"); printf("Testing default keys using NESTED authentication...\n");
struct thread_key_args *def = calloc(1, sizeof(struct thread_key_args)); struct thread_key_args *def = calloc(1, sizeof(struct thread_key_args));
if (def == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
def->thread = 0; def->thread = 0;
def->idx = 0; def->idx = 0;
def->uid = uid; def->uid = uid;
@ -758,6 +762,10 @@ int main(int argc, const char *argv[]) {
// the rest of available threads to EV1 scenario // the rest of available threads to EV1 scenario
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args)); struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
a->xored = xored; a->xored = xored;
a->thread = i; a->thread = i;
a->idx = i; a->idx = i;
@ -780,6 +788,10 @@ int main(int argc, const char *argv[]) {
// the rest of available threads to EV1 scenario // the rest of available threads to EV1 scenario
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args)); struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
a->xored = xored; a->xored = xored;
a->thread = i; a->thread = i;
a->idx = i; a->idx = i;
@ -823,6 +835,10 @@ int main(int argc, const char *argv[]) {
// threads // threads
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_key_args *b = calloc(1, sizeof(struct thread_key_args)); struct thread_key_args *b = calloc(1, sizeof(struct thread_key_args));
if (b == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
b->thread = i; b->thread = i;
b->idx = i; b->idx = i;
b->uid = uid; b->uid = uid;

View file

@ -290,6 +290,10 @@ int main(int argc, const char *argv[]) {
// threads // threads
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args)); struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i; a->thread = i;
a->idx = i; a->idx = i;
a->uid = uid; a->uid = uid;

View file

@ -277,6 +277,10 @@ int main(int argc, char *argv[]) {
uint64_t stop_time = time(NULL); uint64_t stop_time = time(NULL);
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args)); struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i; a->thread = i;
a->idx = i; a->idx = i;
a->starttime = start_time; a->starttime = start_time;

View file

@ -471,6 +471,10 @@ int main(int argc, char *argv[]) {
uint64_t stop_time = time(NULL); uint64_t stop_time = time(NULL);
for (int i = 0; i < thread_count; ++i) { for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args)); struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i; a->thread = i;
a->idx = i; a->idx = i;
a->generator_idx = g_idx; a->generator_idx = g_idx;