mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
cppcheck nullPointerOutOfMemory
This commit is contained in:
@@ -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);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -901,6 +901,10 @@ static int CmdLegicDump(const char *Cmd) {
|
||||
PrintAndLogEx(SUCCESS, "Reading tag memory." NOLF);
|
||||
|
||||
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->iv = 0x55;
|
||||
payload->len = dumplen;
|
||||
|
||||
@@ -542,6 +542,10 @@ 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");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
while (old->next != NULL) {
|
||||
old = old->next;
|
||||
|
||||
@@ -858,6 +858,10 @@ static int CmdFdxBSim(const char *Cmd) {
|
||||
PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _YELLOW_("%04u-%"PRIu64), country_code, national_code);
|
||||
|
||||
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) {
|
||||
PrintAndLogEx(ERR, "Error with tag bitstream generation.");
|
||||
free(bs);
|
||||
@@ -866,6 +870,11 @@ 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.");
|
||||
free(bs);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->encoding = 2;
|
||||
payload->invert = 1;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -363,6 +363,10 @@ static int CmdGallagherSim(const char *Cmd) {
|
||||
bytes_to_bytebits(raw, sizeof(raw), 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->invert = 0;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -387,6 +387,10 @@ 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.");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->encoding = 2;
|
||||
payload->invert = 0;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -1678,7 +1678,12 @@ static int CmdLFHitagEload(const char *Cmd) {
|
||||
// check dump len..
|
||||
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)
|
||||
payload->type = 1;
|
||||
|
||||
@@ -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
|
||||
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->invert = 0;
|
||||
payload->clock = 32;
|
||||
@@ -756,6 +760,10 @@ 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");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->carrier = 2;
|
||||
payload->invert = 0;
|
||||
payload->clock = 32;
|
||||
|
||||
@@ -251,6 +251,10 @@ static int CmdIOProxSim(const char *Cmd) {
|
||||
// arg2 --- Invert and clk setting
|
||||
// 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");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->fchigh = 10;
|
||||
payload->fclow = 8;
|
||||
payload->separator = 1;
|
||||
|
||||
@@ -284,6 +284,11 @@ static int CmdJablotronSim(const char *Cmd) {
|
||||
getJablotronBits(fullcode, bs);
|
||||
|
||||
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->invert = 1;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -346,6 +346,10 @@ static int CmdKeriSim(const char *Cmd) {
|
||||
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64), internalid);
|
||||
|
||||
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->invert = 0;
|
||||
payload->clock = 32;
|
||||
|
||||
@@ -539,6 +539,10 @@ 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");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->encoding = 2;
|
||||
payload->invert = 1;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -423,7 +423,17 @@ static int CmdNexWatchClone(const char *Cmd) {
|
||||
blocks[0] = 0x00042080;
|
||||
|
||||
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));
|
||||
if (res == NULL) {
|
||||
PrintAndLogEx(FAILED, "Memory allocation failed for res");
|
||||
free(res_shifted);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
bytes_to_bytebits(raw, 12, res);
|
||||
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)));
|
||||
|
||||
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->invert = 0;
|
||||
payload->clock = 32;
|
||||
|
||||
@@ -261,6 +261,10 @@ static int CmdNoralsySim(const char *Cmd) {
|
||||
PrintAndLogEx(SUCCESS, "Simulating Noralsy - CardId: " _YELLOW_("%u") " year " _YELLOW_("%u"), id, year);
|
||||
|
||||
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->invert = 0;
|
||||
payload->separator = 1;
|
||||
|
||||
@@ -368,6 +368,10 @@ 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");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->invert = 0;
|
||||
payload->separator = 0;
|
||||
payload->clock = 32;
|
||||
|
||||
@@ -446,6 +446,10 @@ static int CmdParadoxSim(const char *Cmd) {
|
||||
uint8_t clk = 50, high = 10, low = 8;
|
||||
|
||||
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->fclow = low;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -333,6 +333,10 @@ static int CmdPrescoSim(const char *Cmd) {
|
||||
getPrescoBits(fullcode, 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->invert = 0;
|
||||
payload->separator = 1;
|
||||
|
||||
@@ -428,6 +428,10 @@ 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");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
payload->fchigh = 10;
|
||||
payload->fclow = 8;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -270,6 +270,10 @@ static int CmdSecurakeySim(const char *Cmd) {
|
||||
bytes_to_bytebits(raw, sizeof(raw), 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->invert = 0;
|
||||
payload->separator = 0;
|
||||
|
||||
@@ -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 *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(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)" : "");
|
||||
@@ -358,6 +366,14 @@ 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");
|
||||
free(r0);
|
||||
free(r1);
|
||||
free(r2);
|
||||
free(r3);
|
||||
return;
|
||||
}
|
||||
snprintf(r4, r_len, "try all downlink modes %s", (dl_mode_def == 4) ? "(def)" : "");
|
||||
at[n++] = arg_lit0(NULL, "all", r4);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user