util/misc_util: Fix unchecked error

It's unlikely, but let's check for ftell() errors.

BUG=b:64477774
BRANCH=none
TEST=none

Change-Id: I3690da60f756ab056e852e9f485b3c439c82e67b
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Found-by: Coverity Scan #58158
Reviewed-on: https://chromium-review.googlesource.com/719196
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Martin Roth <martinroth@chromium.org>
This commit is contained in:
Patrick Georgi
2017-10-13 17:45:49 +02:00
committed by chrome-bot
parent b6547eda9b
commit 87dbec5dfa

View File

@@ -48,8 +48,11 @@ char *read_file(const char *filename, int *size)
fseek(f, 0, SEEK_END);
*size = ftell(f);
rewind(f);
if (*size > 0x100000) {
fprintf(stderr, "File seems unreasonably large\n");
if ((*size > 0x100000) || (*size < 0)) {
if (*size < 0)
perror("ftell failed");
else
fprintf(stderr, "File seems unreasonably large\n");
fclose(f);
return NULL;
}