mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-30 10:39:04 +00:00
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>
This commit is contained in:
parent
e428b127e7
commit
0e78af22d9
@ -97,6 +97,7 @@ int read_to_buf(const struct file_info *fdata, char *buf)
|
|||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
|
size_t read;
|
||||||
|
|
||||||
f = fopen(fdata->file_name, "r");
|
f = fopen(fdata->file_name, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
@ -104,9 +105,8 @@ int read_to_buf(const struct file_info *fdata, char *buf)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
read = fread(buf, fdata->file_size, 1, f);
|
||||||
fread(buf, fdata->file_size, 1, f);
|
if (ferror(f) || read != 1) {
|
||||||
if (errno != 0) {
|
|
||||||
ERRS("unable to read from file \"%s\"", fdata->file_name);
|
ERRS("unable to read from file \"%s\"", fdata->file_name);
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user