diff options
author | Mattias Hansson | 2021-11-24 13:10:49 +0100 |
---|---|---|
committer | Stefano Babic | 2022-02-05 13:38:39 +0100 |
commit | eb1c716c6dd14e8fe97ea9a1a2211c27edf3cfb2 (patch) | |
tree | 630d9165b5ed9fdd0d422ec929f946d66d607167 /tools/mxsimage.c | |
parent | c4c1ed68c1e85ed3100840e395d40294d38f5f7c (diff) |
tools/mxsimage: Remove fclose on empty FILE pointer
If `sb_load_cmdfile()` fails to open the configuration file it will jump
to error handling where the code will try to `fclose()` the FILE pointer
which is NULL causing `mkimage` to segfault.
This patch removes the label for error handling and instead returns
immediately which skips the `fclose()` and prevents the segfault. The
errno is also described in the error message to guide users.
Signed-off-by: Mattias Hansson <hansson.mattias@gmail.com>
Reviewed-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'tools/mxsimage.c')
-rw-r--r-- | tools/mxsimage.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/tools/mxsimage.c b/tools/mxsimage.c index 002f4b525aa..fee022aab46 100644 --- a/tools/mxsimage.c +++ b/tools/mxsimage.c @@ -1595,8 +1595,11 @@ static int sb_load_cmdfile(struct sb_image_ctx *ictx) size_t len; fp = fopen(ictx->cfg_filename, "r"); - if (!fp) - goto err_file; + if (!fp) { + fprintf(stderr, "ERR: Failed to load file \"%s\": \"%s\"\n", + ictx->cfg_filename, strerror(errno)); + return -EINVAL; + } while ((rlen = getline(&line, &len, fp)) > 0) { memset(&cmd, 0, sizeof(cmd)); @@ -1616,12 +1619,6 @@ static int sb_load_cmdfile(struct sb_image_ctx *ictx) fclose(fp); return 0; - -err_file: - fclose(fp); - fprintf(stderr, "ERR: Failed to load file \"%s\"\n", - ictx->cfg_filename); - return -EINVAL; } static int sb_build_tree_from_cfg(struct sb_image_ctx *ictx) |