Skip to content

mkimage: fit: check cmd string for buffer overflow #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tools/fit_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int fit_handle_file(struct image_tool_params *params)
if (strlen (params->imagefile) +
strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) {
fprintf (stderr, "%s: Image file name (%s) too long, "
"can't create tmpfile",
"can't create tmpfile\n",
params->imagefile, params->cmdname);
return (EXIT_FAILURE);
}
Expand All @@ -105,13 +105,17 @@ static int fit_handle_file(struct image_tool_params *params)
/* We either compile the source file, or use the existing FIT image */
if (params->datafile) {
/* dtc -I dts -O dtb -p 500 datafile > tmpfile */
snprintf(cmd, sizeof(cmd), "%s %s %s > %s",
ret = snprintf(cmd, sizeof(cmd), "%s %s %s > %s",
MKIMAGE_DTC, params->dtc, params->datafile, tmpfile);
debug("Trying to execute \"%s\"\n", cmd);
} else {
snprintf(cmd, sizeof(cmd), "cp %s %s",
ret = snprintf(cmd, sizeof(cmd), "cp %s %s",
params->imagefile, tmpfile);
}
debug("Trying to execute \"%s\"\n", cmd);
if (ret >= sizeof(cmd)) {
fprintf (stderr, "Command too long, can't create fit image\n");
return (EXIT_FAILURE);
}
if (system (cmd) == -1) {
fprintf (stderr, "%s: system(%s) failed: %s\n",
params->cmdname, cmd, strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion tools/mkimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static inline ulong map_to_sysmem(void *ptr)
#define MKIMAGE_TMPFILE_SUFFIX ".tmp"
#define MKIMAGE_MAX_TMPFILE_LEN 256
#define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
#define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
#define MKIMAGE_MAX_DTC_CMDLINE_LEN 1024
#define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */

#endif /* _MKIIMAGE_H_ */