diff mbox series

[u-boot-mvebu,06/31] tools: kwbimage: Don't crash when binary file name does not contain '/'

Message ID 20210708173032.27999-7-marek.behun@nic.cz
State Superseded
Delegated to: Stefan Roese
Headers show
Series kwboot / kwbimage improvements | expand

Commit Message

Marek Behún July 8, 2021, 5:30 p.m. UTC
From: Pali Rohár <pali@kernel.org>

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>
---
 tools/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefan Roese July 15, 2021, 8:35 a.m. UTC | #1
On 08.07.21 19:30, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> 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>

Thanks,
Stefan

> ---
>   tools/kwbimage.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index 44bf5ee026..c08fb678d4 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);
>   	}
>   
> 


Viele Grüße,
Stefan
diff mbox series

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 44bf5ee026..c08fb678d4 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);
 	}