fix: mem leaks.

This commit is contained in:
iceman1001 2019-02-21 16:17:49 +01:00
commit 6d63b3fbed
9 changed files with 28 additions and 12 deletions

View file

@ -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]);

View file

@ -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 };

View file

@ -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;
} }
@ -1972,6 +1976,7 @@ out:
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;
} }

View file

@ -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;
} }

View file

@ -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;

View file

@ -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));

View file

@ -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 );

View file

@ -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;
} }

View file

@ -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");