]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
Fixed several issues found using a coverity-scan
[proxmark3-svn] / client / cmdhfmf.c
index 9ccfef95c3b5ff53a3b4c6fe804dcadce070dfed..4b591f0f6195caf01c2f40d4ba1e2ca95779d02d 100644 (file)
@@ -572,17 +572,19 @@ int CmdHF14AMfDump(const char *Cmd)
                        uint8_t isOK  = resp.arg[0] & 0xff;\r
                        uint8_t *data  = resp.d.asBytes;\r
                        if (isOK){\r
-                               rights[sectorNo][0] = ((data[7] & 0x10)>>4) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>2);\r
-                               rights[sectorNo][1] = ((data[7] & 0x20)>>5) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>3);\r
-                               rights[sectorNo][2] = ((data[7] & 0x40)>>6) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>4);\r
-                               rights[sectorNo][3] = ((data[7] & 0x80)>>7) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>5);\r
+                               rights[sectorNo][0] = ((data[7] & 0x10)>>2) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>4); // C1C2C3 for data area 0\r
+                               rights[sectorNo][1] = ((data[7] & 0x20)>>3) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>5); // C1C2C3 for data area 1\r
+                               rights[sectorNo][2] = ((data[7] & 0x40)>>4) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>6); // C1C2C3 for data area 2\r
+                               rights[sectorNo][3] = ((data[7] & 0x80)>>5) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>7); // C1C2C3 for sector trailer\r
                        } else {\r
                                PrintAndLog("Could not get access rights for sector %2d. Trying with defaults...", sectorNo);\r
-                               rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = rights[sectorNo][3] = 0x01;\r
+                               rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00;\r
+                               rights[sectorNo][3] = 0x01;\r
                        }\r
                } else {\r
                        PrintAndLog("Command execute timeout when trying to read access rights for sector %2d. Trying with defaults...", sectorNo);\r
-                       rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = rights[sectorNo][3] = 0x01;\r
+                       rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00;\r
+                       rights[sectorNo][3] = 0x01;\r
                }\r
        }\r
        \r
@@ -603,12 +605,12 @@ int CmdHF14AMfDump(const char *Cmd)
                                received = WaitForResponseTimeout(CMD_ACK,&resp,1500);\r
                        } else {                                                                                                // data block. Check if it can be read with key A or key B\r
                                uint8_t data_area = sectorNo<32?blockNo:blockNo/5;\r
-                               if ((rights[sectorNo][data_area] == 3) || (rights[sectorNo][data_area] == 5)) {                 // only key B would work\r
+                               if ((rights[sectorNo][data_area] == 0x03) || (rights[sectorNo][data_area] == 0x05)) {   // only key B would work\r
                                        UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + blockNo, 1, 0}};\r
                                        memcpy(c.d.asBytes, keyB[sectorNo], 6);\r
                                        SendCommand(&c);\r
                                        received = WaitForResponseTimeout(CMD_ACK,&resp,1500);\r
-                               } else if (rights[sectorNo][data_area] == 7) {                                                                                  // no key would work\r
+                               } else if (rights[sectorNo][data_area] == 0x07) {                                                                               // no key would work\r
                                        isOK = false;\r
                                        PrintAndLog("Access rights do not allow reading of sector %2d block %3d", sectorNo, blockNo);\r
                                } else {                                                                                                                                                                // key A would work\r
@@ -1002,6 +1004,16 @@ int CmdHF14AMfNested(const char *Cmd)
 \r
 int CmdHF14AMfChk(const char *Cmd)\r
 {\r
+       if (strlen(Cmd)<3) {\r
+               PrintAndLog("Usage:  hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
+               PrintAndLog("          * - all sectors");\r
+               PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
+               PrintAndLog("d - write keys to binary file\n");\r
+               PrintAndLog("      sample: hf mf chk 0 A 1234567890ab keys.dic");\r
+               PrintAndLog("              hf mf chk *1 ? t");\r
+               return 0;\r
+       }       \r
+\r
        FILE * f;\r
        char filename[256]={0};\r
        char buf[13];\r
@@ -1019,6 +1031,7 @@ int CmdHF14AMfChk(const char *Cmd)
        int transferToEml = 0;\r
        int createDumpFile = 0;\r
 \r
+\r
        keyBlock = calloc(stKeyBlock, 6);\r
        if (keyBlock == NULL) return 1;\r
 \r
@@ -1045,15 +1058,6 @@ int CmdHF14AMfChk(const char *Cmd)
                num_to_bytes(defaultKeys[defaultKeyCounter], 6, (uint8_t*)(keyBlock + defaultKeyCounter * 6));\r
        }\r
        \r
-       if (strlen(Cmd)<3) {\r
-               PrintAndLog("Usage:  hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
-               PrintAndLog("          * - all sectors");\r
-               PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
-               PrintAndLog("d - write keys to binary file\n");\r
-               PrintAndLog("      sample: hf mf chk 0 A 1234567890ab keys.dic");\r
-               PrintAndLog("              hf mf chk *1 ? t");\r
-               return 0;\r
-       }       \r
        \r
        if (param_getchar(Cmd, 0)=='*') {\r
                blockNo = 3;\r
@@ -1142,11 +1146,11 @@ int CmdHF14AMfChk(const char *Cmd)
                                        keycnt++;\r
                                        memset(buf, 0, sizeof(buf));\r
                                }\r
+                               fclose(f);\r
                        } else {\r
                                PrintAndLog("File: %s: not found or locked.", filename);\r
                                free(keyBlock);\r
                                return 1;\r
-                       fclose(f);\r
                        }\r
                }\r
        }\r
@@ -1584,8 +1588,8 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
 int CmdHF14AMfCSetUID(const char *Cmd)\r
 {\r
        uint8_t wipeCard = 0;\r
-       uint8_t uid[8];\r
-       uint8_t oldUid[8];\r
+       uint8_t uid[8] = {0};\r
+       uint8_t oldUid[8]= {0};\r
        int res;\r
 \r
        if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
Impressum, Datenschutz