diff options
author | Patrick Georgi <pgeorgi@google.com> | 2017-10-13 17:45:49 +0200 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-10-19 05:15:31 -0700 |
commit | 87dbec5dfa4e0341d6714ec42c2648448bfec1f7 (patch) | |
tree | c9d169244120b3a628f6831f4e437a3632df3946 /util | |
parent | b6547eda9b90face1a5df01ecd65e10d2c03c5ca (diff) | |
download | chrome-ec-87dbec5dfa4e0341d6714ec42c2648448bfec1f7.tar.gz |
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>
Diffstat (limited to 'util')
-rw-r--r-- | util/misc_util.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/util/misc_util.c b/util/misc_util.c index 3e4ff71f0f..40977dd607 100644 --- a/util/misc_util.c +++ b/util/misc_util.c @@ -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; } |