mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
fix: mem leaks.
This commit is contained in:
parent
44392c6afc
commit
6d63b3fbed
9 changed files with 28 additions and 12 deletions
|
@ -242,7 +242,7 @@ static void printSep() {
|
||||||
PrintAndLogEx(NORMAL, "------------------------------------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "------------------------------------------------------------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace,uint16_t tracelen) {
|
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) {
|
||||||
if (tracepos+19 >= tracelen)
|
if (tracepos+19 >= tracelen)
|
||||||
return tracelen;
|
return tracelen;
|
||||||
|
|
||||||
|
@ -273,8 +273,8 @@ uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace,uint16_t tracelen) {
|
||||||
case 0x0c: PrintAndLogEx(NORMAL, "S_PAD12: %s",line);break;
|
case 0x0c: PrintAndLogEx(NORMAL, "S_PAD12: %s",line);break;
|
||||||
case 0x0d: PrintAndLogEx(NORMAL, "S_PAD13: %s",line);break;
|
case 0x0d: PrintAndLogEx(NORMAL, "S_PAD13: %s",line);break;
|
||||||
case 0x0E: {
|
case 0x0E: {
|
||||||
uint32_t regA = trace[3] + (trace[4]>>8) + (trace[5]>>16) + (trace[6]>>24);
|
uint32_t regA = trace[3] | trace[4] << 8 | trace[5] << 16 | trace[ 6] << 24;
|
||||||
uint32_t regB = trace[7] + (trace[8]>>8) + (trace[9]>>16) + (trace[10]>>24);
|
uint32_t regB = trace[7] | trace[8] << 8 | trace[9] << 16 | trace[10] << 24;
|
||||||
line[0] = 0;
|
line[0] = 0;
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
snprintf(line+( j * 2),110, "%02x", trace[j+11]);
|
snprintf(line+( j * 2),110, "%02x", trace[j+11]);
|
||||||
|
|
|
@ -2163,7 +2163,7 @@ int CmdHFiClassLookUp(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t CSN[8];
|
uint8_t CSN[8];
|
||||||
uint8_t EPURSE[8] = { 0,0,0,0,0,0,0,0 };
|
uint8_t EPURSE[8] = { 0,0,0,0,0,0,0,0 };
|
||||||
uint8_t MACS[8];
|
uint8_t MACS[8]= { 0,0,0,0,0,0,0,0 };
|
||||||
uint8_t CCNR[12];
|
uint8_t CCNR[12];
|
||||||
uint8_t MAC_TAG[4] = { 0,0,0,0 };
|
uint8_t MAC_TAG[4] = { 0,0,0,0 };
|
||||||
|
|
||||||
|
|
|
@ -1245,8 +1245,10 @@ int CmdHF14AMfNested(const char *Cmd) {
|
||||||
// Create dump file
|
// Create dump file
|
||||||
if (createDumpFile) {
|
if (createDumpFile) {
|
||||||
fptr = GenerateFilename("hf-mf-", "-key.bin");
|
fptr = GenerateFilename("hf-mf-", "-key.bin");
|
||||||
if (fptr == NULL)
|
if (fptr == NULL) {
|
||||||
|
free(e_sector);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((fkeys = fopen(fptr, "wb")) == NULL) {
|
if ((fkeys = fopen(fptr, "wb")) == NULL) {
|
||||||
PrintAndLogEx(WARNING, "could not create file " _YELLOW_(%s), fptr);
|
PrintAndLogEx(WARNING, "could not create file " _YELLOW_(%s), fptr);
|
||||||
|
@ -1276,6 +1278,8 @@ int CmdHF14AMfNested(const char *Cmd) {
|
||||||
}
|
}
|
||||||
free(e_sector);
|
free(e_sector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(e_sector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1971,7 +1975,8 @@ out:
|
||||||
if (createDumpFile) {
|
if (createDumpFile) {
|
||||||
fptr = GenerateFilename("hf-mf-", "-key.bin");
|
fptr = GenerateFilename("hf-mf-", "-key.bin");
|
||||||
if (fptr == NULL) {
|
if (fptr == NULL) {
|
||||||
free(keyBlock);
|
free(keyBlock);
|
||||||
|
free(e_sector);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1982,6 +1982,7 @@ int CmdHF14AMfURestore(const char *Cmd){
|
||||||
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
if ( !dump ) {
|
if ( !dump ) {
|
||||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
|
fclose(f);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1990,6 +1991,7 @@ int CmdHF14AMfURestore(const char *Cmd){
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if ( bytes_read < 48 ) {
|
if ( bytes_read < 48 ) {
|
||||||
PrintAndLogEx(WARNING, "Error, dump file is too small");
|
PrintAndLogEx(WARNING, "Error, dump file is too small");
|
||||||
|
free(dump);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1022,8 +1022,10 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Selecting card");
|
PrintAndLogEx(INFO, "Selecting card");
|
||||||
if ( !smart_select(false, NULL) )
|
if ( !smart_select(false, NULL) ) {
|
||||||
|
free(buf);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
char* caid = NULL;
|
char* caid = NULL;
|
||||||
|
|
||||||
|
|
|
@ -1807,6 +1807,7 @@ int CmdEMVRoca(const char *cmd) {
|
||||||
PrintAndLogEx(ERR, "Can't create PDOL data.");
|
PrintAndLogEx(ERR, "Can't create PDOL data.");
|
||||||
tlvdb_free(tlvRoot);
|
tlvdb_free(tlvRoot);
|
||||||
DropFieldEx( channel );
|
DropFieldEx( channel );
|
||||||
|
free(pdol_data_tlv);
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
|
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
|
||||||
|
|
|
@ -538,18 +538,19 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
||||||
|
|
||||||
if (fsize < 0) {
|
if (fsize < 0) {
|
||||||
PrintAndLogDevice(WARNING, "Error, when getting filesize");
|
PrintAndLogDevice(WARNING, "Error, when getting filesize");
|
||||||
if (f) fclose(f);
|
fclose(f);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
if ( !dump ) {
|
if ( !dump ) {
|
||||||
PrintAndLogDevice(WARNING, "Failed to allocate memory");
|
PrintAndLogDevice(WARNING, "Failed to allocate memory");
|
||||||
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||||
|
|
||||||
if (f) fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (bytes_read < fsize) {
|
if (bytes_read < fsize) {
|
||||||
PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize );
|
||||||
|
|
|
@ -266,8 +266,8 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
|
||||||
FILE *f = fopen(fileName, "rb");
|
FILE *f = fopen(fileName, "rb");
|
||||||
if ( !f ) {
|
if ( !f ) {
|
||||||
PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_(%s)"'", fileName);
|
PrintAndLogDevice(WARNING, "file not found or locked. '" _YELLOW_(%s)"'", fileName);
|
||||||
retval = 1;
|
free(fileName);
|
||||||
goto out;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get filesize in order to malloc memory
|
// get filesize in order to malloc memory
|
||||||
|
@ -310,7 +310,12 @@ int loadFile(const char *preferredName, const char *suffix, void* data, size_t*
|
||||||
|
|
||||||
out:
|
out:
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
|
||||||
free(fileName);
|
free(fileName);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,7 +685,7 @@ static bool readKeyFile(uint8_t key[8]) {
|
||||||
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
|
sprintf(filename, "%s.bin", "client/loclass/iclass_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( filename == NULL )
|
if ( strlen(filename) == 0 )
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
FILE *f = fopen(filename, "rb");
|
FILE *f = fopen(filename, "rb");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue