From: Pali Rohár Date: Fri, 23 Jul 2021 09:14:00 +0000 (+0200) Subject: tools: kwbimage: Don't crash when binary file name does not contain '/' X-Git-Tag: v2025.01-rc5-pxa1908~1770^2~41 X-Git-Url: http://git.dujemihanovic.xyz/contact?a=commitdiff_plain;h=4efbf1c3273788b83dd1f7646d26ce9950e4b4dc;p=u-boot.git tools: kwbimage: Don't crash when binary file name does not contain '/' 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 Reviewed-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Chris Packham Tested-by: Chris Packham --- diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c65a40ecb7..724459fb8e 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -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); }