[PATCH] addrmap: Fix off by one in addrmap_set_entry()
Dan Carpenter
dan.carpenter at linaro.org
Thu Jul 27 12:56:38 CEST 2023
On Wed, Jul 26, 2023 at 06:49:44PM -0600, Simon Glass wrote:
> 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.
>
If we hit this error path there probably isn't a reasonable way to
recover. Maybe we could add a WARN()?
regards,
dan carpenter
More information about the U-Boot
mailing list