]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: Coverity Scan warnings on not using the fread return value.
authoriceman1001 <iceman@iuse.se>
Tue, 19 Jan 2016 18:52:01 +0000 (19:52 +0100)
committericeman1001 <iceman@iuse.se>
Tue, 19 Jan 2016 18:52:01 +0000 (19:52 +0100)
client/cmdhficlass.c
client/cmdhfmf.c
client/cmdhfmfhard.c
client/cmdlfhitag.c
client/loclass/ikeys.c

index cf0128bebfee930f73633589dbff6268fb300642..70c18aba204a518419b3eb8df37633de3a03dc66 100644 (file)
@@ -1044,7 +1044,8 @@ int CmdHFiClassCloneTag(const char *Cmd) {
        // else we have to create a share memory
        int i;
        fseek(f,startblock*8,SEEK_SET);
-       if ( fread(tag_data,sizeof(iclass_block_t),endblock - startblock + 1,f) == 0){
+       size_t bytes_read = fread(tag_data,sizeof(iclass_block_t),endblock - startblock + 1,f);
+       if ( bytes_read == 0){
                PrintAndLog("File reading error.");
                fclose(f);
                return 2;
index cf0f5c131199aad6eaf59d937377b1e6149de272..b189e19bfaafe712dd9e5efe73dfe15c1a2a75cd 100644 (file)
@@ -312,8 +312,10 @@ int CmdHF14AMfDump(const char *Cmd)
        }\r
        \r
        // Read keys A from file\r
+       size_t bytes_read;\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
-               if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
+               bytes_read = fread( keyA[sectorNo], 1, 6, fin );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
                        return 2;\r
@@ -322,7 +324,8 @@ int CmdHF14AMfDump(const char *Cmd)
        \r
        // Read keys B from file\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
-               if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
+               bytes_read = fread( keyB[sectorNo], 1, 6, fin );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
                        return 2;\r
@@ -479,8 +482,10 @@ int CmdHF14AMfRestore(const char *Cmd)
                return 1;\r
        }\r
        \r
+       size_t bytes_read;\r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
-               if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
+               bytes_read = fread( keyA[sectorNo], 1, 6, fkeys );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
                        return 2;\r
@@ -488,7 +493,8 @@ int CmdHF14AMfRestore(const char *Cmd)
        }\r
 \r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
-               if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
+               bytes_read = fread( keyB[sectorNo], 1, 6, fkeys );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
                        return 2;\r
index fbfeeb768e38c9174ad3d862f9f7cc32dab1b596..f506f4fda4c3c7687be04b37f029b08a345fedc2 100644 (file)
@@ -626,7 +626,8 @@ static int read_nonce_file(void)
        }
 
        PrintAndLog("Reading nonces from file nonces.bin...");
-       if (fread(read_buf, 1, 6, fnonces) == 0) {
+       size_t bytes_read = fread(read_buf, 1, 6, fnonces);
+       if ( bytes_read == 0) {
                PrintAndLog("File reading error.");
                fclose(fnonces);
                return 1;
index bd2e47a8fbd34a62ac837ac8c8c77e40a58dbfdf..81822eb69875c162c8dae4da20c6198ffe0569a7 100644 (file)
@@ -173,7 +173,8 @@ int CmdLFHitagSim(const char *Cmd) {
                        return 1;
                }
                tag_mem_supplied = true;
-               if (fread(c.d.asBytes,48,1,pf) == 0) {
+               size_t bytes_read = fread(c.d.asBytes, 48, 1, pf);
+               if ( bytes_read == 0) {
                        PrintAndLog("Error: File reading error");
                        fclose(pf);
                        return 1;
index b21ecdbc028f96bdc0ae95cc08f65d9f7c7c6099..73da2ce6cd686b7bd0320c090a2531f2f19053a3 100644 (file)
@@ -740,14 +740,15 @@ int readKeyFile(uint8_t key[8])
        FILE *f;
        int retval = 1;
        f = fopen("iclass_key.bin", "rb");
-       if (f)
-       {
-               if(fread(key, sizeof(uint8_t), 8, f) == 1) 
-               {
-                       retval = 0;     
-               }
-               fclose(f);
+       if (!f) {
+               return 0;
+       }
+       
+       size_t bytes_read = fread(key, sizeof(uint8_t), 8, f);
+       if ( bytes_read == 1) {
+               retval = 0;     
        }
+       fclose(f);
        return retval;
 }
 
@@ -758,11 +759,9 @@ int doKeyTests(uint8_t debuglevel)
 
        prnlog("[+] Checking if the master key is present (iclass_key.bin)...");
        uint8_t key[8] = {0};
-       if(readKeyFile(key))
-       {
+       if(readKeyFile(key)) {
                prnlog("[+] Master key not present, will not be able to do all testcases");
-       }else
-       {
+       } else {
 
                //Test if it's the right key...
                uint8_t i;
Impressum, Datenschutz