[PATCH] addrmap: Fix off by one in addrmap_set_entry()

Simon Glass sjg at google.com
Thu Jul 27 02:49:44 CEST 2023


Hi Dan,

On Tue, 25 Jul 2023 at 09:40, Dan Carpenter <dan.carpenter at linaro.org> wrote:
>
> The > comparison needs to be changed to >= to prevent an out of bounds
> write on th next line.
>
> Signed-off-by: Dan Carpenter <dan.carpenter at linaro.org>
> ---
>  lib/addr_map.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/addr_map.c b/lib/addr_map.c
> index 9b3e0a544e47..86e932e4b561 100644
> --- a/lib/addr_map.c
> +++ b/lib/addr_map.c
> @@ -59,7 +59,7 @@ void *addrmap_phys_to_virt(phys_addr_t paddr)
>  void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
>                         phys_size_t size, int idx)
>  {
> -       if (idx > CONFIG_SYS_NUM_ADDR_MAP)
> +       if (idx >= CONFIG_SYS_NUM_ADDR_MAP)
>                 return;

It looks like this function should return an error.

>
>         address_map[idx].vaddr = vaddr;
> --
> 2.39.2
>

Regards,
Simon


More information about the U-Boot mailing list