]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
FIX: Coverity , Argument can't be negative, CID #121323, ftell(f) can be negative...
[proxmark3-svn] / client / cmdhficlass.c
index ffcd719efadb4d5b4dc6bc6bc73643eaac314021..86524cd6c51e049f9fef6de36a6d945e9bd8dc71 100644 (file)
@@ -269,10 +269,9 @@ int CmdHFiClassELoad(const char *Cmd) {
        //File handling and reading
        FILE *f;
        char filename[FILE_PATH_SIZE];
-       if(opt == 'f' && param_getstr(Cmd, 1, filename) > 0)
-       {
+       if(opt == 'f' && param_getstr(Cmd, 1, filename) > 0) {
                f = fopen(filename, "rb");
-       }else{
+       } else {
                return hf_iclass_eload_usage();
        }
 
@@ -285,8 +284,13 @@ int CmdHFiClassELoad(const char *Cmd) {
        long fsize = ftell(f);
        fseek(f, 0, SEEK_SET);
 
-       uint8_t *dump = malloc(fsize);
+       if (fsize < 0)  {
+               prnlog("Error, when getting filesize");
+               fclose(f);
+               return 1;
+       }
 
+       uint8_t *dump = malloc(fsize);
 
        size_t bytes_read = fread(dump, 1, fsize, f);
        fclose(f);
@@ -409,6 +413,7 @@ int CmdHFiClassDecrypt(const char *Cmd) {
 
        saveFile(outfilename,"bin", decrypted, blocknum*8);
 
+       free(decrypted);
        return 0;
 }
 
@@ -1504,6 +1509,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