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>
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));
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)