tools: mkimage: Fix nullptr at strchr() The 'file' pointer can be null. Thus, before using it in the strchr() function, you need to make sure that it is not null.
PATCH 1/1 tools: mkimage: Fix nullptr at strchr() The 'file' pointer can be null. Thus, before using it in the strchr() function, you need to make sure that it is not null.
--- tools/mkimage.c | 2 ++ 1 file changed, 2 insertions(+)
tools/mkimage.c +2 -0
@@ -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' ;
Signature · 1 line
2.17.1
Hi,
Quoted 6 lines · Mikhail Ilin
Fixes 0b0c6af38738 ("Prepare v2020.01")Signed-off-by Mikhail Ilin <[email protected]>--- tools/mkimage.c | 2 ++ 1 file changed, 2 insertions(+)
Please can you add a commit message and keep your subject to 50 chars?
For the fixes tag, can you find a commit rather than the merge thing?
Quoted 15 lines
tools/mkimage.c +2
-1@@ -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' ; --
Quoted 2 lines
2.17.1
Regards,
SImon
PATCH v2 1/1 tools: mkimage: Fix nullptr at strchr()
The 'file' pointer can be null. Thus, before using it in the strchr() function, you need to make sure that it is not null.
--- tools/mkimage.c | 2 ++ 1 file changed, 2 insertions(+)
tools/mkimage.c +2 -0
@@ -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' ;
Signature · 1 line
2.17.1
Re: [PATCH v2] tools: mkimage: Fix nullptr at strchr()
Quoted 14 lines · Mikhail Ilin
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 <[email protected]>--- tools/mkimage.c | 2 ++ 1 file changed, 2 insertions(+)tools/mkimage.c +0
-0
tools/mkimage.c int main(int argc, char **argv) · line 513
Quoted 5 lines
tools/mkimage.c +2
-0@@ -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.
tools/mkimage.c int main(int argc, char **argv) · line 514
Quoted 1 line
tools/mkimage.c +0
-0char *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
Quoted 2 lines
tools/mkimage.c +0
-0if (sep) { *sep ='\0' ;
PATCH v3 1/1 tools: mkimage: Fix nullptr at strchr()
The copy_datafile(ifd, params.datafile) function has been implemented to copy data by reducing the number of lines in the main function.
--- tools/mkimage.c | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
tools/mkimage.c +19 -0
@@ -430,6 +430,24 @@ static void verify_image(const struct image_type_params *tparams) (void )close (ifd); } +void copy_datafile (int ifd,char *file) +{ +if (!file) +return ; +for (;;) { +char *sep =strchr (file,':' ); + +if (sep) { + *sep ='\0' ; +copy_file (ifd, file,1 ); + *sep++ =':' ; + file = sep; + }else { +copy_file (ifd, file,0 ); +break ; + } + } +} +int main (int argc,char **argv) {
int ifd = -1;
@@ -647,21 +666,7 @@ int main(int argc, char **argv)
file = NULL;
}
}
-
- file = params.datafile;
-
- for (;;) {
- char *sep = strchr(file, ':');
- if (sep) {
- *sep = '\0';
- copy_file (ifd, file, 1);
- *sep++ = ':';
- file = sep;
- } else {
- copy_file (ifd, file, 0);
- break;
- }
- }
+ copy_datafile(ifd, params.datafile)
} else if (params.type == IH_TYPE_PBLIMAGE) {
/* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms);
Signature · 1 line
2.17.1
Re: [PATCH v3] tools: mkimage: Fix nullptr at strchr()
Quoted 5 lines · Mikhail Ilin
The
copy_datafile(ifd, params.datafile)function has been
implemented to copy data by reducing the number of lines in the main function.Signed-off-by Mikhail Ilin <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom