]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
FIX: Coverity, resource leaks 'nd more.. in "lf t55xx bruteforce" nasty piece of...
[proxmark3-svn] / client / cmdlft55xx.c
index a86dd42328400781c9cb7c9635ce210bb5dd5ead..10461754fe11f85af2d7898426e9e140ac650a78 100644 (file)
@@ -1387,7 +1387,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
     bool found = false;\r
 \r
     char cmdp = param_getchar(Cmd, 0);\r
     bool found = false;\r
 \r
     char cmdp = param_getchar(Cmd, 0);\r
-    if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();\r
+    if (cmdp == 'h' || cmdp == 'H') {\r
+               free(keyBlock);\r
+               return usage_t55xx_bruteforce();\r
+       }\r
 \r
        if (cmdp == 'i' || cmdp == 'I') {\r
        \r
 \r
        if (cmdp == 'i' || cmdp == 'I') {\r
        \r
@@ -1423,6 +1426,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                                if (!p) {\r
                                        PrintAndLog("Cannot allocate memory for defaultKeys");\r
                                        free(keyBlock);\r
                                if (!p) {\r
                                        PrintAndLog("Cannot allocate memory for defaultKeys");\r
                                        free(keyBlock);\r
+                                       fclose(f);\r
                                        return 2;\r
                                }\r
                                keyBlock = p;\r
                                        return 2;\r
                                }\r
                                keyBlock = p;\r
@@ -1437,6 +1441,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                \r
                if (keycnt == 0) {\r
                        PrintAndLog("No keys found in file");\r
                \r
                if (keycnt == 0) {\r
                        PrintAndLog("No keys found in file");\r
+                       free(keyBlock);\r
                        return 1;\r
                }\r
                PrintAndLog("Loaded %d keys", keycnt);\r
                        return 1;\r
                }\r
                PrintAndLog("Loaded %d keys", keycnt);\r
@@ -1448,6 +1453,8 @@ int CmdT55xxBruteForce(const char *Cmd) {
                        if (ukbhit()) {\r
                                getchar();\r
                                printf("\naborted via keyboard!\n");\r
                        if (ukbhit()) {\r
                                getchar();\r
                                printf("\naborted via keyboard!\n");\r
+                               free(keyBlock);\r
+                               free(p);\r
                                return 0;\r
                        }\r
                \r
                                return 0;\r
                        }\r
                \r
@@ -1458,6 +1465,8 @@ int CmdT55xxBruteForce(const char *Cmd) {
                        \r
                        if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
                                PrintAndLog("Aquireing data from device failed. Quitting");\r
                        \r
                        if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
                                PrintAndLog("Aquireing data from device failed. Quitting");\r
+                               free(keyBlock);\r
+                               free(p);\r
                                return 0;\r
                        }\r
                        \r
                                return 0;\r
                        }\r
                        \r
@@ -1465,10 +1474,14 @@ int CmdT55xxBruteForce(const char *Cmd) {
 \r
                        if ( found ) {\r
                                PrintAndLog("Found valid password: [%08X]", testpwd);\r
 \r
                        if ( found ) {\r
                                PrintAndLog("Found valid password: [%08X]", testpwd);\r
+                               free(keyBlock);\r
+                               free(p);\r
                                return 0;\r
                        } \r
                }\r
                PrintAndLog("Password NOT found.");\r
                                return 0;\r
                        } \r
                }\r
                PrintAndLog("Password NOT found.");\r
+               free(keyBlock);\r
+               free(p);\r
                return 0;\r
        }\r
        \r
                return 0;\r
        }\r
        \r
@@ -1478,7 +1491,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
     start_password = param_get32ex(Cmd, 0, 0, 16);\r
        end_password = param_get32ex(Cmd, 1, 0, 16);\r
        \r
     start_password = param_get32ex(Cmd, 0, 0, 16);\r
        end_password = param_get32ex(Cmd, 1, 0, 16);\r
        \r
-       if ( start_password >= end_password ) return usage_t55xx_bruteforce();\r
+       if ( start_password >= end_password ) {\r
+               free(keyBlock);\r
+               return usage_t55xx_bruteforce();\r
+       }\r
        \r
     PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
        \r
        \r
     PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
        \r
@@ -1491,11 +1507,13 @@ int CmdT55xxBruteForce(const char *Cmd) {
                if (ukbhit()) {\r
                        getchar();\r
                        printf("\naborted via keyboard!\n");\r
                if (ukbhit()) {\r
                        getchar();\r
                        printf("\naborted via keyboard!\n");\r
+                       free(keyBlock);\r
                        return 0;\r
                }\r
                        \r
                if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
                        PrintAndLog("Aquireing data from device failed. Quitting");\r
                        return 0;\r
                }\r
                        \r
                if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
                        PrintAndLog("Aquireing data from device failed. Quitting");\r
+                       free(keyBlock);\r
                        return 0;\r
                }\r
                found = tryDetectModulation();\r
                        return 0;\r
                }\r
                found = tryDetectModulation();\r
@@ -1510,6 +1528,8 @@ int CmdT55xxBruteForce(const char *Cmd) {
                PrintAndLog("Found valid password: [%08x]", i);\r
     else\r
                PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
                PrintAndLog("Found valid password: [%08x]", i);\r
     else\r
                PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
+\r
+       free(keyBlock);\r
     return 0;\r
 }\r
 \r
     return 0;\r
 }\r
 \r
Impressum, Datenschutz