mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-16 10:03:04 -07:00
fix a sanity memory leak with reserving memory used only for json file loading..
This commit is contained in:
parent
550fa5aa8f
commit
8243ac9749
6 changed files with 71 additions and 71 deletions
|
@ -1978,12 +1978,7 @@ static int CmdHF15Restore(const char *Cmd) {
|
|||
PrintAndLogEx(INFO, "Using block size... %d", blocksize);
|
||||
|
||||
// 4bytes * 256 blocks. Should be enough..
|
||||
uint8_t *data = calloc(4 * 256, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *data = NULL;
|
||||
size_t datalen = 0;
|
||||
int res = PM3_SUCCESS;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
|
@ -1997,7 +1992,12 @@ static int CmdHF15Restore(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, data, 256 * 4, &datalen, NULL);
|
||||
data = calloc(4 * 256, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)data, 256 * 4, &datalen, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
|
@ -899,12 +899,7 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
CLIParserFree(ctx);
|
||||
|
||||
size_t bytes_read = 2048;
|
||||
uint8_t *dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
int res = 0;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
switch (dftype) {
|
||||
|
@ -917,7 +912,12 @@ static int CmdHFiClassELoad(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, 2048, &bytes_read, NULL);
|
||||
dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, 2048, &bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
@ -1134,13 +1134,8 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
}
|
||||
|
||||
size_t decryptedlen = 2048;
|
||||
uint8_t *decrypted = calloc(2048, sizeof(uint8_t));
|
||||
uint8_t *decrypted = NULL;
|
||||
bool have_file = false;
|
||||
if (decrypted == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
int res = PM3_SUCCESS;
|
||||
|
||||
// if user supplied dump file, time to load it
|
||||
|
@ -1157,7 +1152,12 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, decrypted, 2048, &decryptedlen, NULL);
|
||||
decrypted = calloc(2048, sizeof(uint8_t));
|
||||
if (decrypted == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)decrypted, 2048, &decryptedlen, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
@ -2037,12 +2037,7 @@ static int CmdHFiClassRestore(const char *Cmd) {
|
|||
}
|
||||
|
||||
size_t bytes_read = 2048;
|
||||
uint8_t *dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
int res = PM3_SUCCESS;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
switch (dftype) {
|
||||
|
@ -2055,7 +2050,12 @@ static int CmdHFiClassRestore(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, 2048, &bytes_read, NULL);
|
||||
dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, 2048, &bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
@ -2539,12 +2539,7 @@ static int CmdHFiClassView(const char *Cmd) {
|
|||
CLIParserFree(ctx);
|
||||
|
||||
size_t bytes_read = 2048;
|
||||
uint8_t *dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
int res = 0;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
switch (dftype) {
|
||||
|
@ -2557,7 +2552,12 @@ static int CmdHFiClassView(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, 2048, &bytes_read, NULL);
|
||||
dump = calloc(2048, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, 2048, &bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
|
@ -3750,12 +3750,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
|
|||
PrintAndLogEx(INFO, "overriding number of blocks, will use %d blocks ( %u bytes )", block_cnt, block_cnt * block_width);
|
||||
}
|
||||
|
||||
uint8_t *data = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *data = NULL;
|
||||
size_t datalen = 0;
|
||||
int res = PM3_SUCCESS;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
|
@ -3769,7 +3764,12 @@ int CmdHF14AMfELoad(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, data, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &datalen, NULL);
|
||||
data = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)data, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &datalen, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
@ -4422,12 +4422,7 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
|
|||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t *data = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *data = NULL;
|
||||
size_t bytes_read = 0;
|
||||
int res = 0;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
|
@ -4441,7 +4436,12 @@ static int CmdHF14AMfCLoad(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, data, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &bytes_read, NULL);
|
||||
data = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (data == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)data, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
@ -5921,12 +5921,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
|||
CLIParserFree(ctx);
|
||||
|
||||
// reserve memory
|
||||
uint8_t *dump = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
size_t bytes_read = 0;
|
||||
int res = 0;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
|
@ -5940,7 +5935,12 @@ static int CmdHF14AMfView(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &bytes_read, NULL);
|
||||
dump = calloc(MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, MIFARE_4K_MAXBLOCK * MFBLOCK_SIZE, &bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
|
@ -130,12 +130,7 @@ static void print_info_result(uint8_t *data, bool verbose) {
|
|||
|
||||
static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len, size_t *bytes_read) {
|
||||
|
||||
uint8_t *dump = calloc(DUMP_FILESIZE, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
int res = PM3_SUCCESS;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
switch (dftype) {
|
||||
|
@ -148,7 +143,12 @@ static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, DUMP_FILESIZE, bytes_read, NULL);
|
||||
dump = calloc(DUMP_FILESIZE, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, DUMP_FILESIZE, bytes_read, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
|
@ -257,7 +257,7 @@ static int CmdLFHitagEload(const char *Cmd) {
|
|||
PrintAndLogEx(ERR, "error, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, dump, dumplen, &dumplen, NULL);
|
||||
res = loadFileJSON(filename, (void *)dump, dumplen, &dumplen, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
|
@ -2347,12 +2347,7 @@ static int CmdT55xxRestore(const char *Cmd) {
|
|||
}
|
||||
|
||||
size_t dlen = 0;
|
||||
uint8_t *dump = calloc(T55x7_BLOCK_COUNT * 4, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
DumpFileType_t dftype = getfiletype(filename);
|
||||
switch (dftype) {
|
||||
case BIN: {
|
||||
|
@ -2364,7 +2359,12 @@ static int CmdT55xxRestore(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
case JSON: {
|
||||
res = loadFileJSON(filename, dump, T55x7_BLOCK_COUNT * 4, &dlen, NULL);
|
||||
dump = calloc(T55x7_BLOCK_COUNT * 4, sizeof(uint8_t));
|
||||
if (dump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileJSON(filename, (void *)dump, T55x7_BLOCK_COUNT * 4, &dlen, NULL);
|
||||
break;
|
||||
}
|
||||
case DICTIONARY: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue