Message ID | 20221123071021.10286-1-ilin.mikhail.ol@gmail.com |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Series | [v2] tools: mkimage: Fix nullptr at strchr() | expand |
On 11/23/22 08:10, Mikhail Ilin wrote: > The 'file' pointer can be null. Thus, before using it in the > strchr() function, you need to make sure that it is not null. > > Fixes: d1be8f922eb3 ("mkimage: Fix variable length header support") > Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com> > --- > tools/mkimage.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/mkimage.c b/tools/mkimage.c > index 5f51d2cc89..95005d8414 100644 > --- a/tools/mkimage.c > +++ b/tools/mkimage.c > @@ -509,6 +509,8 @@ int main(int argc, char **argv) > file = params.datafile; > > for (;;) { > + if (!file) > + break; The main function is now 370 lines long. It really should be restructured into smaller functions to make it readable. I would prefer if you would pull out a function copy_datafile(ifd, params.datafile) for copying the data file. > char *sep = strchr(file, ':'); We don't want variable definitions in the middle of the code. Please, move the declaration to the top of the code block. Best regards Heinrich > if (sep) { > *sep = '\0';
diff --git a/tools/mkimage.c b/tools/mkimage.c index 5f51d2cc89..95005d8414 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -509,6 +509,8 @@ int main(int argc, char **argv) file = params.datafile; for (;;) { + if (!file) + break; char *sep = strchr(file, ':'); if (sep) { *sep = '\0';
The 'file' pointer can be null. Thus, before using it in the strchr() function, you need to make sure that it is not null. Fixes: d1be8f922eb3 ("mkimage: Fix variable length header support") Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com> --- tools/mkimage.c | 2 ++ 1 file changed, 2 insertions(+)