]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
More coverity fixes
authorMartin Holst Swende <martin@swende.se>
Thu, 30 Oct 2014 20:49:18 +0000 (21:49 +0100)
committerMartin Holst Swende <martin@swende.se>
Thu, 30 Oct 2014 20:49:18 +0000 (21:49 +0100)
armsrc/iso14443a.c
client/cmdhfmf.c
client/loclass/cipherutils.c
client/loclass/fileutils.c
client/mifarehost.c
client/uart.c

index bbfc0b75b92352ba39cfd7d99a1b5a7469d5cdd1..01cf24868868856c3c4ca8d81e7faaf9806984d1 100644 (file)
@@ -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. 
       //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;
     }
 
       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;
        //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 ;
        uint32_t cuid;
 
        uint32_t nt =0 ;
index 80d93a46659e74950b4aa68e20488588e4a28534..bdb0e7e744f93848541e0d941214dcce34bfc0b1 100644 (file)
@@ -667,12 +667,15 @@ int CmdHF14AMfRestore(const char *Cmd)
        }\r
        if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) {\r
                PrintAndLog("Could not find file dumpkeys.bin");\r
        }\r
        if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) {\r
                PrintAndLog("Could not find file dumpkeys.bin");\r
+               fclose(fdump);\r
                return 1;\r
        }\r
        \r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
                if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                return 1;\r
        }\r
        \r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
                if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
+                       fclose(fdump);\r
+                       fclose(fkeys);\r
                        return 2;\r
                }\r
        }\r
                        return 2;\r
                }\r
        }\r
@@ -680,9 +683,12 @@ int CmdHF14AMfRestore(const char *Cmd)
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
                if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
                if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
+                       fclose(fdump);\r
+                       fclose(fkeys);\r
                        return 2;\r
                }\r
        }\r
                        return 2;\r
                }\r
        }\r
+       fclose(fkeys);\r
 \r
        PrintAndLog("Restoring dumpdata.bin to card");\r
 \r
 \r
        PrintAndLog("Restoring dumpdata.bin to card");\r
 \r
@@ -693,6 +699,7 @@ int CmdHF14AMfRestore(const char *Cmd)
                        \r
                        if (fread(bldata, 1, 16, fdump) == 0) {\r
                                PrintAndLog("File reading error (dumpdata.bin).");\r
                        \r
                        if (fread(bldata, 1, 16, fdump) == 0) {\r
                                PrintAndLog("File reading error (dumpdata.bin).");\r
+                               fclose(fdump);\r
                                return 2;\r
                        }\r
                                        \r
                                return 2;\r
                        }\r
                                        \r
@@ -727,7 +734,6 @@ int CmdHF14AMfRestore(const char *Cmd)
        }\r
        \r
        fclose(fdump);\r
        }\r
        \r
        fclose(fdump);\r
-       fclose(fkeys);\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
index 1e08cf10526fa969811bb97d795f54f05df7d427..e11e8d2247caf7bda75f66837d1be1c7c05687e7 100644 (file)
@@ -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);
                cx += snprintf(output+cx,outsize-cx, "%02x ",*(arr+i));
        }
        prnlog(output);
+       free(output);
 }
 
 //-----------------------------
 }
 
 //-----------------------------
index 2f7b6b6554405771334297b054a24ddc064b4d50..8c08c9ee30d54ce4c82e06efea9af533f2fe536a 100644 (file)
@@ -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);
        FILE *fileHandle=fopen(fileName,"wb");
        if(!fileHandle) {
                prnlog("Failed to write to file '%s'", fileName);
+               free(fileName);
                return 1;
        }
        fwrite(data, 1, datalen, fileHandle);
                return 1;
        }
        fwrite(data, 1, datalen, fileHandle);
index 72e70662a16f5486bcf6751da25e1574ae86c2c1..2a1f8a48e9d38a3d003200cab970fd1c9c4239d3 100644 (file)
@@ -350,13 +350,15 @@ int loadTraceCard(uint8_t *tuid) {
        while(!feof(f)){\r
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
        while(!feof(f)){\r
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
-      PrintAndLog("File reading error.");\r
+                       PrintAndLog("File reading error.");\r
+                       fclose(f);\r
                        return 2;\r
                        return 2;\r
-    }\r
+       }\r
 \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
 \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
+                       fclose(f);\r
                        return 2;\r
                }\r
                for (i = 0; i < 32; i += 2)\r
                        return 2;\r
                }\r
                for (i = 0; i < 32; i += 2)\r
index f7c5e35c3b0d7ad0a04c950c0ab55d328712933b..4b2fee994f533d0044c729f36ce01690c113a8aa 100644 (file)
@@ -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
   // 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;
   }
 
     return CLAIMED_SERIAL_PORT;
   }
 
Impressum, Datenschutz