From 664bb5ae720fb546a459dc6e60b3864d7ecd56ca Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 13 May 2015 14:08:59 +0200 Subject: [PATCH] BUGS: more Coverity scan fixes. --- armsrc/BigBuf.c | 2 +- client/cmdhfmf.c | 4 +++- client/cmdscript.c | 2 +- client/mifarehost.c | 10 ++-------- client/scripting.c | 3 ++- client/util.c | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 2fb50a47..51fafdeb 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -173,7 +173,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ // parity bytes if (iLen != 0) { if (parity != NULL) { - memcpy(trace + traceLen, parity, num_paritybytes); + memcpy(trace + traceLen, parity, num_paritybytes); } else { memset(trace + traceLen, 0x00, num_paritybytes); } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index a4986f6b..1b815326 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1202,7 +1202,7 @@ int CmdHF14AMfELoad(const char *Cmd) if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; - fnameptr += len; + fnameptr += len-4; sprintf(fnameptr, ".eml"); @@ -1593,6 +1593,7 @@ int CmdHF14AMfCLoad(const char *Cmd) if (fgets(buf, sizeof(buf), f) == NULL) { PrintAndLog("File reading error."); + fclose(f); return 2; } @@ -1600,6 +1601,7 @@ int CmdHF14AMfCLoad(const char *Cmd) if(strlen(buf) && feof(f)) break; PrintAndLog("File content error. Block data must include 32 HEX symbols"); + fclose(f); return 2; } for (i = 0; i < 32; i += 2) diff --git a/client/cmdscript.c b/client/cmdscript.c index 928a216d..fd02d13a 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -83,7 +83,7 @@ int CmdList(const char *Cmd) { while ((ep = readdir (dp)) != NULL) { - if(ep->d_name != NULL && str_ends_with(ep->d_name, ".lua")) + if( str_ends_with(ep->d_name, ".lua")) PrintAndLog("%-16s %s", ep->d_name, "A script file"); } (void) closedir (dp); diff --git a/client/mifarehost.c b/client/mifarehost.c index 873213d1..d754b06b 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -356,10 +356,7 @@ int loadTraceCard(uint8_t *tuid) { FillFileNameByUID(traceFileName, tuid, ".eml", 7); f = fopen(traceFileName, "r"); - if (!f) { - fclose(f); - return 1; - } + if (!f) return 1; blockNum = 0; @@ -396,10 +393,7 @@ int saveTraceCard(void) { if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0; f = fopen(traceFileName, "w+"); - if ( !f ) { - fclose(f); - return 1; - } + if ( !f ) return 1; for (int i = 0; i < 64; i++) { // blocks for (int j = 0; j < 16; j++) // bytes diff --git a/client/scripting.c b/client/scripting.c index 15c336ff..880b7cb2 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -341,7 +341,8 @@ int setLuaPath( lua_State* L, const char* path ) lua_pushstring( L, buf ); // push the new one lua_setfield( L, -2, "path" ); // set the field "path" in table at -2 with value at top of stack lua_pop( L, 1 ); // get rid of package table from top of stack - return 0; // all done! + free(buf); + return 0; // all done! } diff --git a/client/util.c b/client/util.c index 382c85c6..1c8081bf 100644 --- a/client/util.c +++ b/client/util.c @@ -124,7 +124,7 @@ char *sprint_hex(const uint8_t *data, const size_t len) { char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) { - int maxLen = ( len > 1024) ? 1024 : len; + int maxLen = ( len > 1020) ? 1020 : len; static char buf[1024]; memset(buf, 0x00, 1024); char *tmp = buf; -- 2.39.5