@@ -96,7 +96,7 @@ static int fit_handle_file(struct image_tool_params *params)
96
96
if (strlen (params -> imagefile ) +
97
97
strlen (MKIMAGE_TMPFILE_SUFFIX ) + 1 > sizeof (tmpfile )) {
98
98
fprintf (stderr , "%s: Image file name (%s) too long, "
99
- "can't create tmpfile" ,
99
+ "can't create tmpfile\n " ,
100
100
params -> imagefile , params -> cmdname );
101
101
return (EXIT_FAILURE );
102
102
}
@@ -105,13 +105,17 @@ static int fit_handle_file(struct image_tool_params *params)
105
105
/* We either compile the source file, or use the existing FIT image */
106
106
if (params -> datafile ) {
107
107
/* dtc -I dts -O dtb -p 500 datafile > tmpfile */
108
- snprintf (cmd , sizeof (cmd ), "%s %s %s > %s" ,
108
+ ret = snprintf (cmd , sizeof (cmd ), "%s %s %s > %s" ,
109
109
MKIMAGE_DTC , params -> dtc , params -> datafile , tmpfile );
110
- debug ("Trying to execute \"%s\"\n" , cmd );
111
110
} else {
112
- snprintf (cmd , sizeof (cmd ), "cp %s %s" ,
111
+ ret = snprintf (cmd , sizeof (cmd ), "cp %s %s" ,
113
112
params -> imagefile , tmpfile );
114
113
}
114
+ debug ("Trying to execute \"%s\"\n" , cmd );
115
+ if (ret >= sizeof (cmd )) {
116
+ fprintf (stderr , "Command too long, can't create fit image\n" );
117
+ return (EXIT_FAILURE );
118
+ }
115
119
if (system (cmd ) == -1 ) {
116
120
fprintf (stderr , "%s: system(%s) failed: %s\n" ,
117
121
params -> cmdname , cmd , strerror (errno ));
0 commit comments