diff options
author | Patrick Georgi <pgeorgi@google.com> | 2019-09-09 22:59:20 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-12 11:42:07 +0000 |
commit | ccd8d9409114b58e552bb466d4d074f326dd551b (patch) | |
tree | 32e3e8f2035c40f80b731478eac214bc1d6360ab | |
parent | 69d0f6e2c66c164bd4de5d279ace4b303db04f1b (diff) | |
download | chrome-ec-ccd8d9409114b58e552bb466d4d074f326dd551b.tar.gz |
util/ecst.c: Catch errors in remaining fseek calls
There's little reason why fseek should fail, but when it does, we're
not looking where we think we look.
Found by Coverity Scan #58144
BUG=none
BRANCH=none
TEST=none
Change-Id: I7a784cb96def611ae5802d530882eb14daf58ce1
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1793585
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
-rw-r--r-- | util/ecst.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/util/ecst.c b/util/ecst.c index e1b0c6b35c..01c2151dc7 100644 --- a/util/ecst.c +++ b/util/ecst.c @@ -1299,7 +1299,8 @@ int get_file_length(FILE *stream) file_len = ftell(stream); /* Restore the original position. */ - fseek(stream, current_position, SEEK_SET); + if (fseek(stream, current_position, SEEK_SET) < 0) + return -1; /* return file length. */ return file_len; @@ -1877,7 +1878,9 @@ int calc_header_crc_bin(unsigned int *p_cksum) init_calculation(&calc_header_checksum_crc); /* Go thru the BIN File and calculate the Checksum */ - fseek(g_hfd_pointer, 0x00000000, SEEK_SET); + if (fseek(g_hfd_pointer, 0x00000000, SEEK_SET) < 0) + return 0; + if (fread(g_header_array, HEADER_SIZE, 1, @@ -2128,7 +2131,8 @@ int main_hdr(void) return FALSE; } - fseek(g_hdr_pointer, 0L, SEEK_SET); + if (fseek(g_hdr_pointer, 0L, SEEK_SET) < 0) + return FALSE; tmp_long_val = HDR_PTR_SIGNATURE; result = (int)(fwrite(&tmp_long_val, |