FIX: Coverity Scan warnings on not using the fread return value.

This commit is contained in:
iceman1001 2016-01-19 19:52:01 +01:00
parent 52cf34c1cc
commit 841d7af0dc
5 changed files with 26 additions and 18 deletions

View 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;

View file

@ -312,8 +312,10 @@ int CmdHF14AMfDump(const char *Cmd)
}
// Read keys A from file
size_t bytes_read;
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {
bytes_read = fread( keyA[sectorNo], 1, 6, fin );
if ( bytes_read == 0) {
PrintAndLog("File reading error.");
fclose(fin);
return 2;
@ -322,7 +324,8 @@ int CmdHF14AMfDump(const char *Cmd)
// Read keys B from file
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {
bytes_read = fread( keyB[sectorNo], 1, 6, fin );
if ( bytes_read == 0) {
PrintAndLog("File reading error.");
fclose(fin);
return 2;
@ -479,8 +482,10 @@ int CmdHF14AMfRestore(const char *Cmd)
return 1;
}
size_t bytes_read;
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {
bytes_read = fread( keyA[sectorNo], 1, 6, fkeys );
if ( bytes_read == 0) {
PrintAndLog("File reading error (dumpkeys.bin).");
fclose(fkeys);
return 2;
@ -488,7 +493,8 @@ int CmdHF14AMfRestore(const char *Cmd)
}
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {
bytes_read = fread( keyB[sectorNo], 1, 6, fkeys );
if ( bytes_read == 0) {
PrintAndLog("File reading error (dumpkeys.bin).");
fclose(fkeys);
return 2;

View 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;

View 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;

View 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;