From 4efbf1c3273788b83dd1f7646d26ce9950e4b4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Fri, 23 Jul 2021 11:14:00 +0200 Subject: tools: kwbimage: Don't crash when binary file name does not contain '/' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/kwbimage.c b/tools/kwbimage.c index c65a40e..724459f 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); } -- cgit v1.1