From: iceman1001 Date: Tue, 12 Jan 2016 21:43:28 +0000 (+0100) Subject: FIX, Coverity, Argument can't be negative. CID# 212322, ftell(f) can be negative... X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/9c4e28a44540d6314c93558cc0ad162af86e63cc?hp=7144c99b0765f6995e7a954030bfcb5bb2d441d0 FIX, Coverity, Argument can't be negative. CID# 212322, ftell(f) can be negative. Not allowed in malloc... --- diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 75c45444..d4750735 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -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,9 +284,14 @@ 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"); + return 1; + } + uint8_t *dump = malloc(fsize); + size_t bytes_read = fread(dump, 1, fsize, f); fclose(f);