]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwbimage: Don't crash when binary file name does not contain '/'
authorPali Rohár <pali@kernel.org>
Fri, 23 Jul 2021 09:14:00 +0000 (11:14 +0200)
committerStefan Roese <sr@denx.de>
Sat, 31 Jul 2021 07:49:31 +0000 (09:49 +0200)
In the case when the file name is specified relative to the current
working directory, it does not contain '/' character and strrchr()
returns NULL.

The following strcmp() function then crashes on NULL pointer
dereference.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Chris Packham <judge.packham@gmail.com>
Tested-by: Chris Packham <judge.packham@gmail.com>
tools/kwbimage.c

index c65a40ecb73a658d89162d958e3353e128d87a83..724459fb8e4708c81b3f53d0bdaf1d9f1be75435 100644 (file)
@@ -1277,7 +1277,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
        if (e) {
                char *s = strrchr(e->binary.file, '/');
 
-               if (strcmp(s, "/binary.0") == 0)
+               if (s && strcmp(s, "/binary.0") == 0)
                        main_hdr->destaddr = cpu_to_le32(params->addr);
        }