aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils
diff options
context:
space:
mode:
authorMathias Kresin <dev@kresin.me>2019-01-05 07:40:55 +0100
committerMathias Kresin <dev@kresin.me>2019-01-13 18:31:10 +0100
commit0e78af22d95d91f7c2fdfc66fac993c6c5d349d8 (patch)
tree64f827000c8d815e44291ec69f46e5a6af9faaef /tools/firmware-utils
parente428b127e7c9964a20cfd4cfb30b43262a10bfbe (diff)
downloadupstream-0e78af22d95d91f7c2fdfc66fac993c6c5d349d8.tar.gz
upstream-0e78af22d95d91f7c2fdfc66fac993c6c5d349d8.tar.bz2
upstream-0e78af22d95d91f7c2fdfc66fac993c6c5d349d8.zip
firmware-utils: mkdlinkfw: fix error handling
fread() doesn't set errno, ferror need to be used to check for errors. While at it, check if we read the expect number of elements. Signed-off-by: Mathias Kresin <dev@kresin.me>
Diffstat (limited to 'tools/firmware-utils')
-rw-r--r--tools/firmware-utils/src/mkdlinkfw-lib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.c b/tools/firmware-utils/src/mkdlinkfw-lib.c
index 3b71fda7db..b3f3f41348 100644
--- a/tools/firmware-utils/src/mkdlinkfw-lib.c
+++ b/tools/firmware-utils/src/mkdlinkfw-lib.c
@@ -97,6 +97,7 @@ int read_to_buf(const struct file_info *fdata, char *buf)
{
FILE *f;
int ret = EXIT_FAILURE;
+ size_t read;
f = fopen(fdata->file_name, "r");
if (f == NULL) {
@@ -104,9 +105,8 @@ int read_to_buf(const struct file_info *fdata, char *buf)
goto out;
}
- errno = 0;
- fread(buf, fdata->file_size, 1, f);
- if (errno != 0) {
+ read = fread(buf, fdata->file_size, 1, f);
+ if (ferror(f) || read != 1) {
ERRS("unable to read from file \"%s\"", fdata->file_name);
goto out_close;
}