]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
More coverity findings
authorMartin Holst Swende <martin@swende.se>
Mon, 27 Oct 2014 21:33:37 +0000 (22:33 +0100)
committerMartin Holst Swende <martin@swende.se>
Mon, 27 Oct 2014 21:33:37 +0000 (22:33 +0100)
client/cmdhfmf.c
client/cmdlfhitag.c
client/loclass/ikeys.c
client/mifarehost.c

index 4b591f0f6195caf01c2f40d4ba1e2ca95779d02d..80d93a46659e74950b4aa68e20488588e4a28534 100644 (file)
@@ -343,10 +343,6 @@ int CmdHF14AMfURdCard(const char *Cmd)
     uint8_t isOK  = 0;\r
     uint8_t * data  = NULL;\r
 \r
     uint8_t isOK  = 0;\r
     uint8_t * data  = NULL;\r
 \r
-    if (sectorNo > 15) {\r
-        PrintAndLog("Sector number must be less than 16");\r
-        return 1;\r
-    }\r
     PrintAndLog("Attempting to Read Ultralight... ");\r
         \r
        UsbCommand c = {CMD_MIFAREU_READCARD, {sectorNo}};\r
     PrintAndLog("Attempting to Read Ultralight... ");\r
         \r
        UsbCommand c = {CMD_MIFAREU_READCARD, {sectorNo}};\r
@@ -359,64 +355,24 @@ int CmdHF14AMfURdCard(const char *Cmd)
 \r
         PrintAndLog("isOk:%02x", isOK);\r
         if (isOK) \r
 \r
         PrintAndLog("isOk:%02x", isOK);\r
         if (isOK) \r
-            for (i = 0; i < 16; i++) {\r
-                       switch(i){\r
-                               case 2:\r
-                                       //process lock bytes\r
-                                       lockbytes_t=data+(i*4);\r
-                                       lockbytes[0]=lockbytes_t[2];\r
-                                       lockbytes[1]=lockbytes_t[3];\r
-                                       for(int j=0; j<16; j++){\r
-                                               bit[j]=lockbytes[j/8] & ( 1 <<(7-j%8));\r
-                                       }\r
-                                       //PrintAndLog("LB %02x %02x", lockbytes[0],lockbytes[1]);\r
-                                       //PrintAndLog("LB2b %02x %02x %02x %02x %02x %02x %02x %02x",bit[8],bit[9],bit[10],bit[11],bit[12],bit[13],bit[14],bit[15]);            \r
-                                       PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));\r
-                                       break;\r
-                               case 3: \r
-                                       PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[4]);\r
-                                       break;\r
-                               case 4:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[3]);\r
-                                       break;\r
-                               case 5:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[2]);\r
-                                       break;\r
-                               case 6:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[1]);\r
-                                       break;\r
-                               case 7:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[0]);\r
-                                       break;\r
-                               case 8:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[15]);\r
-                                       break;\r
-                               case 9:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[14]);\r
-                                       break;\r
-                               case 10:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[13]);\r
-                                       break;\r
-                               case 11:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[12]);\r
-                                       break;\r
-                               case 12:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[11]);\r
-                                       break;\r
-                               case 13:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[10]);\r
-                                       break;\r
-                               case 14:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[9]);\r
-                                       break;\r
-                               case 15:\r
-                    PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[8]);\r
-                                       break;\r
-                               default:\r
-                                       PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));\r
-                                       break;\r
+               {       // bit 0 and 1\r
+                               PrintAndLog("Block %3d:%s ", 0,sprint_hex(data + 0 * 4, 4));\r
+                               PrintAndLog("Block %3d:%s ", 1,sprint_hex(data + 1 * 4, 4));\r
+                               // bit 2\r
+                               //process lock bytes\r
+                               lockbytes_t=data+(2*4);\r
+                               lockbytes[0]=lockbytes_t[2];\r
+                               lockbytes[1]=lockbytes_t[3];\r
+                               for(int j=0; j<16; j++){\r
+                                       bit[j]=lockbytes[j/8] & ( 1 <<(7-j%8));\r
                                }\r
                                }\r
-                        }\r
+                               //remaining\r
+                   for (i = 3; i < 16; i++) {\r
+                       int bitnum = (23-i) % 16;\r
+                                       PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[bitnum]);\r
+                   }\r
+\r
+               }\r
         } else {\r
                 PrintAndLog("Command execute timeout");\r
         }\r
         } else {\r
                 PrintAndLog("Command execute timeout");\r
         }\r
@@ -546,6 +502,7 @@ int CmdHF14AMfDump(const char *Cmd)
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
+                       fclose(fin);\r
                        return 2;\r
                }\r
        }\r
                        return 2;\r
                }\r
        }\r
@@ -553,10 +510,11 @@ int CmdHF14AMfDump(const char *Cmd)
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
                if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
                        PrintAndLog("File reading error.");\r
+                       fclose(fin);\r
                        return 2;\r
                }\r
        }\r
                        return 2;\r
                }\r
        }\r
-       \r
+       fclose(fin);\r
        // Read access rights to sectors\r
 \r
        PrintAndLog("|-----------------------------------------|");\r
        // Read access rights to sectors\r
 \r
        PrintAndLog("|-----------------------------------------|");\r
@@ -666,7 +624,6 @@ int CmdHF14AMfDump(const char *Cmd)
                PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
        }\r
                \r
                PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
        }\r
                \r
-       fclose(fin);\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
@@ -1432,12 +1389,14 @@ int CmdHF14AMfELoad(const char *Cmd)
                                break;\r
                        }\r
                        PrintAndLog("File reading error.");\r
                                break;\r
                        }\r
                        PrintAndLog("File reading error.");\r
+                       fclose(f);\r
                        return 2;\r
                }\r
                if (strlen(buf) < 32){\r
                        if(strlen(buf) && feof(f))\r
                                break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
                        return 2;\r
                }\r
                if (strlen(buf) < 32){\r
                        if(strlen(buf) && feof(f))\r
                                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
@@ -1446,6 +1405,7 @@ int CmdHF14AMfELoad(const char *Cmd)
                }\r
                if (mfEmlSetMem(buf8, blockNum, 1)) {\r
                        PrintAndLog("Cant set emul block: %3d", blockNum);\r
                }\r
                if (mfEmlSetMem(buf8, blockNum, 1)) {\r
                        PrintAndLog("Cant set emul block: %3d", blockNum);\r
+                       fclose(f);\r
                        return 3;\r
                }\r
                blockNum++;\r
                        return 3;\r
                }\r
                blockNum++;\r
index 13f075f7291114d612930caeb642e59d0331aa8b..32d38aebef926dff73284e5ea3688dbe9a651462 100644 (file)
@@ -41,9 +41,6 @@ int CmdLFHitagList(const char *Cmd)
   int i = 0;
   int prev = -1;
 
   int i = 0;
   int prev = -1;
 
-  char filename[256];
-  FILE* pf = NULL;
-  
   for (;;) {
     if(i >= 1900) {
       break;
   for (;;) {
     if(i >= 1900) {
       break;
@@ -107,23 +104,19 @@ int CmdLFHitagList(const char *Cmd)
       line);
 
 
       line);
 
 
-   if (pf) {
-      fprintf(pf," +%7d:  %3d: %s %s\n",
-                                       (prev < 0 ? 0 : (timestamp - prev)),
-                                       bits,
-                                       (isResponse ? "TAG" : "   "),
-                                       line);
-    }
+//   if (pf) {
+//      fprintf(pf," +%7d:  %3d: %s %s\n",
+//                                     (prev < 0 ? 0 : (timestamp - prev)),
+//                                     bits,
+//                                     (isResponse ? "TAG" : "   "),
+//                                     line);
+//    }
        
     prev = timestamp;
     i += (len + 9);
   }
   
        
     prev = timestamp;
     i += (len + 9);
   }
   
-  if (pf) {
-         PrintAndLog("Recorded activity succesfully written to file: %s", filename);
-    fclose(pf);
-  }
-       
+
   return 0;
 }
 
   return 0;
 }
 
index cd2b72ee0e8d0c26872888b025ba7ca479eed102..4749181e3dc395fcdac6fd82c01495c3333de657 100644 (file)
@@ -727,13 +727,17 @@ int readKeyFile(uint8_t key[8])
 {
 
        FILE *f;
 {
 
        FILE *f;
-
+       int retval = 1;
        f = fopen("iclass_key.bin", "rb");
        if (f)
        {
        f = fopen("iclass_key.bin", "rb");
        if (f)
        {
-               if(fread(key, sizeof(key), 1, f) == 1) return 0;
+               if(fread(key, sizeof(uint8_t), 8, f) == 1) 
+               {
+                       retval = 0;     
+               }
+               fclose(f);
        }
        }
-       return 1;
+       return retval;
 
 }
 
 
 }
 
index 7633def36a61bdcf2ea68de25ebc420cc3b0587d..72e70662a16f5486bcf6751da25e1574ae86c2c1 100644 (file)
@@ -497,7 +497,7 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
        break;\r
 \r
        case TRACE_WRITE_OK: \r
        break;\r
 \r
        case TRACE_WRITE_OK: \r
-               if ((len == 1) && (data[0] = 0x0a)) {\r
+               if ((len == 1) && (data[0] == 0x0a)) {\r
                        traceState = TRACE_WRITE_DATA;\r
 \r
                        return 0;\r
                        traceState = TRACE_WRITE_DATA;\r
 \r
                        return 0;\r
@@ -555,23 +555,13 @@ int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEm
                        at_par = parity;\r
                        \r
                        //  decode key here)\r
                        at_par = parity;\r
                        \r
                        //  decode key here)\r
-                       if (!traceCrypto1) {\r
-                               ks2 = ar_enc ^ prng_successor(nt, 64);\r
-                               ks3 = at_enc ^ prng_successor(nt, 96);\r
-                               revstate = lfsr_recovery64(ks2, ks3);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, nr_enc, 1);\r
-                               lfsr_rollback_word(revstate, uid ^ nt, 0);\r
-                       }else{\r
-                               ks2 = ar_enc ^ prng_successor(nt, 64);\r
-                               ks3 = at_enc ^ prng_successor(nt, 96);\r
-                               revstate = lfsr_recovery64(ks2, ks3);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, 0, 0);\r
-                               lfsr_rollback_word(revstate, nr_enc, 1);\r
-                               lfsr_rollback_word(revstate, uid ^ nt, 0);\r
-                       }\r
+                       ks2 = ar_enc ^ prng_successor(nt, 64);\r
+                       ks3 = at_enc ^ prng_successor(nt, 96);\r
+                       revstate = lfsr_recovery64(ks2, ks3);\r
+                       lfsr_rollback_word(revstate, 0, 0);\r
+                       lfsr_rollback_word(revstate, 0, 0);\r
+                       lfsr_rollback_word(revstate, nr_enc, 1);\r
+                       lfsr_rollback_word(revstate, uid ^ nt, 0);\r
                        crypto1_get_lfsr(revstate, &lfsr);\r
                        printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
                        AddLogUint64(logHexFileName, "key> ", lfsr); \r
                        crypto1_get_lfsr(revstate, &lfsr);\r
                        printf("key> %x%x\n", (unsigned int)((lfsr & 0xFFFFFFFF00000000) >> 32), (unsigned int)(lfsr & 0xFFFFFFFF));\r
                        AddLogUint64(logHexFileName, "key> ", lfsr); \r
Impressum, Datenschutz