diff mbox series

[u-boot-marvell,v2,08/20] tools: kwbimage: Check the return value of image_headersz_v1()

Message ID 20220112172054.5961-9-pali@kernel.org
State Accepted
Commit 252e7c3a24fefdf88dfa3fff87e8dc4d0c7aa9cc
Delegated to: Stefan Roese
Headers show
Series tools: kwbimage: Load address fixes | expand

Commit Message

Pali Rohár Jan. 12, 2022, 5:20 p.m. UTC
Function image_headersz_v1() may return zero on fatal errors.
In this case the function already printed an error message.

Check the return value of image_headersz_v1() in kwbimage_generate(),
and exit on zero value with EXIT_FAILURE.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
---
 tools/kwbimage.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stefan Roese Jan. 13, 2022, 6:35 a.m. UTC | #1
On 1/12/22 18:20, Pali Rohár wrote:
> Function image_headersz_v1() may return zero on fatal errors.
> In this case the function already printed an error message.
> 
> Check the return value of image_headersz_v1() in kwbimage_generate(),
> and exit on zero value with EXIT_FAILURE.
> 
> 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 | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tools/kwbimage.c b/tools/kwbimage.c
> index c0f1bdac0210..a5b518f60bc8 100644
> --- a/tools/kwbimage.c
> +++ b/tools/kwbimage.c
> @@ -2029,6 +2029,10 @@ static int kwbimage_generate(struct image_tool_params *params,
>   
>   	case 1:
>   		alloc_len = image_headersz_v1(NULL);
> +		if (!alloc_len) {
> +			free(image_cfg);
> +			exit(EXIT_FAILURE);
> +		}
>   		break;
>   
>   	default:
> 

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index c0f1bdac0210..a5b518f60bc8 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -2029,6 +2029,10 @@  static int kwbimage_generate(struct image_tool_params *params,
 
 	case 1:
 		alloc_len = image_headersz_v1(NULL);
+		if (!alloc_len) {
+			free(image_cfg);
+			exit(EXIT_FAILURE);
+		}
 		break;
 
 	default: