[PATCH] cmd: abootimg: Prevent use of unintialised variable

Tom Rini trini at konsulko.com
Wed Jun 25 16:43:40 CEST 2025


On Wed, Jun 25, 2025 at 12:15:53PM +0100, Andrew Goodbody wrote:
> vhdr can be used when not initialised so detect this condition
> and exit early to prevent the problem.
> 
> This issue was found with Smatch.
> 
> Fixes: 636da2039aea (android: boot: support boot image header version 3 and 4)
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
>  cmd/abootimg.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/cmd/abootimg.c b/cmd/abootimg.c
> index ae7a1a7c83b..6065be9de6a 100644
> --- a/cmd/abootimg.c
> +++ b/cmd/abootimg.c
> @@ -100,16 +100,16 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
>  	hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
>  	if (get_avendor_bootimg_addr() != -1)
>  		vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr));
> +	else
> +		return CMD_RET_FAILURE;

Do we need an unmap_system(hdr) here as well?

>  
>  	if (!android_image_get_data(hdr, vhdr, &img_data)) {
> -		if (get_avendor_bootimg_addr() != -1)
> -			unmap_sysmem(vhdr);
> +		unmap_sysmem(vhdr);
>  		unmap_sysmem(hdr);
>  		return CMD_RET_FAILURE;
>  	}
>  
> -	if (get_avendor_bootimg_addr() != -1)
> -		unmap_sysmem(vhdr);
> +	unmap_sysmem(vhdr);
>  	unmap_sysmem(hdr);
>  
>  	if (img_data.header_version < 2) {
> 
> ---
> base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
> change-id: 20250625-abootimg_fix-51600dc8356a
> 
> Best regards,
> -- 
> Andrew Goodbody <andrew.goodbody at linaro.org>
> 

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250625/85676aa2/attachment.sig>


More information about the U-Boot mailing list