]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
FIX, Coverity, Argument can't be negative. CID# 212322, ftell(f) can …
[proxmark3-svn] / client / cmdhficlass.c
index 99070e18e8d847f0ecf0a61c22b29ce8fc7f9d47..67bcbe766d476e78e116f1982a499fa0efd8aaab 100644 (file)
@@ -283,8 +283,13 @@ int CmdHFiClassELoad(const char *Cmd) {
        long fsize = ftell(f);
        fseek(f, 0, SEEK_SET);
 
-       uint8_t *dump = malloc(fsize);
+       if (fsize < 0) {
+               PrintAndLog("Error, when getting filesize");
+               fclose(f);
+               return 1;
+       }
 
+       uint8_t *dump = malloc(fsize);
 
        size_t bytes_read = fread(dump, 1, fsize, f);
        fclose(f);
@@ -406,7 +411,7 @@ int CmdHFiClassDecrypt(const char *Cmd) {
        fclose(f);
 
        saveFile(outfilename,"bin", decrypted, blocknum*8);
-
+       free(decrypted);
        return 0;
 }
 
@@ -1046,7 +1051,11 @@ int CmdHFiClassCloneTag(const char *Cmd) {
        // else we have to create a share memory
        int i;
        fseek(f,startblock*8,SEEK_SET);
-       fread(tag_data,sizeof(iclass_block_t),endblock - startblock + 1,f);
+       if ( fread(tag_data,sizeof(iclass_block_t),endblock - startblock + 1,f) == 0 ) {
+               PrintAndLog("File reading error.");
+               fclose(f);
+               return 2;
+       }
 
        uint8_t MAC[4]={0x00,0x00,0x00,0x00};
        uint8_t div_key[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
@@ -1498,6 +1507,12 @@ static int loadKeys(char *filename) {
        long fsize = ftell(f);
        fseek(f, 0, SEEK_SET);
 
+       if ( fsize < 0 ) {
+               PrintAndLog("Error, when getting filesize");
+               fclose(f);
+               return 1;
+       }
+
        uint8_t *dump = malloc(fsize);
 
        size_t bytes_read = fread(dump, 1, fsize, f);
Impressum, Datenschutz