[PATCH u-boot-marvell v3 27/39] tools: kwboot: Explicitly check against size of struct main_hdr_v1

Stefan Roese sr at denx.de
Fri Oct 1 08:24:47 CEST 2021


On 24.09.21 23:07, Marek Behún wrote:
> From: Marek Behún <marek.behun at nic.cz>
> 
> Explicitly check the image size against size of struct main_hdr_v1.
> This way the check is more readable, since the `hdrsz` variable
> may semantically contain another value.
> 
> Signed-off-by: Marek Behún <marek.behun at nic.cz>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
>   tools/kwboot.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index 4fae44c46e..77bf5cb80b 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -820,14 +820,14 @@ kwboot_img_patch_hdr(void *img, size_t *size)
>   	struct main_hdr_v1 *hdr;
>   	uint32_t srcaddr;
>   	uint8_t csum;
> -	size_t hdrsz = sizeof(*hdr);
> +	size_t hdrsz;
>   	int image_ver;
>   	int is_secure;
>   
>   	rc = -1;
>   	hdr = img;
>   
> -	if (*size < hdrsz) {
> +	if (*size < sizeof(struct main_hdr_v1)) {
>   		errno = EINVAL;
>   		goto out;
>   	}
> 


Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list