util/misc_util: Fix unchecked error
It's unlikely, but let's check for ftell() errors.
BRANCH=none
TEST=none
Found-by: Coverity Scan
Commit-Ready: Patrick Georgi
Tested-by: Patrick Georgi
@@ -48,7 +48,10 @@ char *read_file(const char *filename, int *size)
fseek(f, 0, SEEK_END);
*size = ftell(f);
rewind(f);
- if (*size > 0x100000) {
+ if ((*size > 0x100000) || (*size < 0)) {
+ if (*size < 0)
+ perror("ftell failed");
+ else
fprintf(stderr, "File seems unreasonably large\n");
fclose(f);
return NULL;
