[PATCH] boot: menu: Do not dereference pointer if pointer is NULL
Tom Rini
trini at konsulko.com
Wed Jul 2 15:44:49 CEST 2025
On Wed, Jul 02, 2025 at 10:18:19AM +0100, Andrew Goodbody wrote:
> On 01/07/2025 21:40, Tom Rini wrote:
> > On Mon, Jun 30, 2025 at 05:06:07PM +0100, Andrew Goodbody wrote:
> >
> > > scene_obj_find can return NULL but this is not checked for before
> > > the return is dereferenced. Add a NULL check.
> > >
> > > This issue was found by Smatch.
> > >
> > > Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> > > ---
> > > boot/scene_menu.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/boot/scene_menu.c b/boot/scene_menu.c
> > > index 17150af145d..9a6e37d1c64 100644
> > > --- a/boot/scene_menu.c
> > > +++ b/boot/scene_menu.c
> > > @@ -508,7 +508,8 @@ int scene_menu_display(struct scene_obj_menu *menu)
> > > return 0;
> > > pointer = scene_obj_find(scn, menu->pointer_id, SCENEOBJT_TEXT);
> > > - pstr = expo_get_str(scn->expo, pointer->str_id);
> > > + if (pointer)
> > > + pstr = expo_get_str(scn->expo, pointer->str_id);
> > > list_for_each_entry(item, &menu->item_head, sibling) {
> > > struct scene_obj_txt *key = NULL, *label = NULL;
> >
> > This is in a slightly different place in -next, and I think the whole
> > function needs to be read and corrected for error handling. I think we
> > then will need to initialize pstr to NULL as well. Thanks.
>
> Hi Tom,
>
> I will rebase to -next and resend. I also added a NULL check for str but I
> am not sure what else might need doing though unless you have some
> suggestions?
> It looks to me as though pstr is not used if pointer is NULL so there should
> be no need to initialise it?
Ah, I had to re-read the code again. We check for pointer before
dereferencing pstr at the end of the list_for_each_entry. Sorry for the
noise.
--
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/20250702/5561fe5e/attachment.sig>
More information about the U-Boot
mailing list