From: Martin Holst Swende Date: Thu, 30 Oct 2014 20:49:18 +0000 (+0100) Subject: More coverity fixes X-Git-Tag: v2.0.0-rc1~86 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/ca4714cd23338a762c45839d1b3010988b7612a7 More coverity fixes --- diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index bbfc0b75..01cf2486 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1730,9 +1730,11 @@ int iso14443a_select_card(byte_t* uid_ptr, iso14a_card_select_t* p_hi14a_card, u //memcpy(uid_resp, uid_resp + 1, 3); // But memcpy should not be used for overlapping arrays, // and memmove appears to not be available in the arm build. - // So this has been replaced with a for-loop: - for(int xx = 0; xx < 3; xx++) uid_resp[xx] = uid_resp[xx+1]; - + // Therefore: + uid_resp[0] = uid_resp[1]; + uid_resp[1] = uid_resp[2]; + uid_resp[2] = uid_resp[3]; + uid_resp_len = 3; } @@ -1939,7 +1941,7 @@ void ReaderMifare(bool first_try) //byte_t par_mask = 0xff; static byte_t par_low = 0; bool led_on = TRUE; - uint8_t uid[10]; + uint8_t uid[10] ={0}; uint32_t cuid; uint32_t nt =0 ; diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 80d93a46..bdb0e7e7 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -667,12 +667,15 @@ int CmdHF14AMfRestore(const char *Cmd) } if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) { PrintAndLog("Could not find file dumpkeys.bin"); + fclose(fdump); return 1; } for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) { PrintAndLog("File reading error (dumpkeys.bin)."); + fclose(fdump); + fclose(fkeys); return 2; } } @@ -680,9 +683,12 @@ int CmdHF14AMfRestore(const char *Cmd) for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) { PrintAndLog("File reading error (dumpkeys.bin)."); + fclose(fdump); + fclose(fkeys); return 2; } } + fclose(fkeys); PrintAndLog("Restoring dumpdata.bin to card"); @@ -693,6 +699,7 @@ int CmdHF14AMfRestore(const char *Cmd) if (fread(bldata, 1, 16, fdump) == 0) { PrintAndLog("File reading error (dumpdata.bin)."); + fclose(fdump); return 2; } @@ -727,7 +734,6 @@ int CmdHF14AMfRestore(const char *Cmd) } fclose(fdump); - fclose(fkeys); return 0; } diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index 1e08cf10..e11e8d22 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -192,6 +192,7 @@ void printarr_human_readable(char * title, uint8_t* arr, int len) cx += snprintf(output+cx,outsize-cx, "%02x ",*(arr+i)); } prnlog(output); + free(output); } //----------------------------- diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c index 2f7b6b65..8c08c9ee 100644 --- a/client/loclass/fileutils.c +++ b/client/loclass/fileutils.c @@ -35,6 +35,7 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si FILE *fileHandle=fopen(fileName,"wb"); if(!fileHandle) { prnlog("Failed to write to file '%s'", fileName); + free(fileName); return 1; } fwrite(data, 1, datalen, fileHandle); diff --git a/client/mifarehost.c b/client/mifarehost.c index 72e70662..2a1f8a48 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -350,13 +350,15 @@ int loadTraceCard(uint8_t *tuid) { while(!feof(f)){ memset(buf, 0, sizeof(buf)); if (fgets(buf, sizeof(buf), f) == NULL) { - PrintAndLog("File reading error."); + PrintAndLog("File reading error."); + fclose(f); return 2; - } + } if (strlen(buf) < 32){ if (feof(f)) break; PrintAndLog("File content error. Block data must include 32 HEX symbols"); + fclose(f); return 2; } for (i = 0; i < 32; i += 2) diff --git a/client/uart.c b/client/uart.c index f7c5e35c..4b2fee99 100644 --- a/client/uart.c +++ b/client/uart.c @@ -73,6 +73,7 @@ serial_port uart_open(const char* pcPortName) // Does the system allows us to place a lock on this file descriptor if (fcntl(sp->fd, F_SETLK, &fl) == -1) { // A conflicting lock is held by another process + free(sp); return CLAIMED_SERIAL_PORT; }