Add fread checking and fix order of parameters.

Not a problem on little endian machines, potentially a problem on big
endian ones.

Thanks Riastradh from freenode.##crypto.
This commit is contained in:
Érico Rolim 2020-10-09 01:04:32 -03:00
parent 4fe7044f17
commit 2075f4b4d2
1 changed files with 4 additions and 1 deletions

View File

@ -94,7 +94,10 @@ static ssize_t open_file_for_read(char *name, uint8_t **buffer)
return -1;
}
fread(*buffer, size, 1, file);
if (fread(*buffer, 1, size, file) != (size_t)size) {
fputs("mismatched file size and bytes read!\n", stderr);
return -1;
}
fclose(file);
return size;