normal/menu_entry: Add grub_calloc failure check
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 24 lines · On 2025-12-02 12:32, [email protected] wrote:
Message: 3
Date: Tue, 2 Dec 2025 12:31:48 +0530
From: Sridhar Markonda <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2] normal/menu_entry: Addgrub_callocfailure check
Message-ID: <[email protected]>Add a NULL check to prevent failure from
grub_callocinupdate_screen. This stops possible NULL pointer dereference and avoids unexpected behavior.Signed-off-by Sridhar Markonda <[email protected]>--- grub-core/normal/menu_entry.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)grub-core/normal/menu_entry.c +0
-0@@ -295,8 +295,12 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
grub-core/normal/menu_entry.c update_screen (struct screen *screen, struct · line 303
Quoted 10 lines
grub-core/normal/menu_entry.c +5
-2pos = linep->pos + (term_screen - screen->terms); -if (!*pos) - *pos =grub_calloc (linep->len +1 ,sizeof (**pos)); +if (*pos ==NULL ) + { + *pos =grub_calloc (linep->len +1 ,sizeof (**pos)); +if (*pos ==NULL ) +return ;
Hi Sridhar,
Thank you so much for the patch!
In my opinion, returning due to grub_calloc failure might not be a good idea here!
To me, it seems grub_print_ucs4_menu() and its corresponding functions which uses 'pos' as a last argument handles NULL properly. So returning based on this argument being NULL might not be a good idea. There are other parts of the code in GRUB where grub_print_ucs4_menu() has been called with this last argument as 0.
Regards,
Avnish Chouhan
Quoted 20 lines
grub-core/normal/menu_entry.c +1
-0+ } if (i == region_start || linep == screen->lines + screen->line|| (i >
region_start&& mode ==ALL_LINES))
--
2.47.3------------------------------
Subject: Digest Footer
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 4 lines
------------------------------
End of Grub-devel Digest, Vol 262, Issue 5
******************************************
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 41 lines · Avnish Chouhan
Quoted 26 lines · On 2025-12-02 12:32, [email protected] wrote:
Message: 3
Date: Tue, 2 Dec 2025 12:31:48 +0530
From: Sridhar Markonda <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2] normal/menu_entry: Addgrub_callocfailure check
Message-ID: <[email protected]>Add a NULL check to prevent failure from
grub_callocinupdate_screen. This stops possible NULL pointer dereference and avoids unexpected behavior.Signed-off-by Sridhar Markonda <[email protected]>--- grub-core/normal/menu_entry.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)grub-core/normal/menu_entry.c +0
-0@@ -295,8 +295,12 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,grub-core/normal/menu_entry.c update_screen (struct screen *screen, struct · line 303
Quoted 10 lines
grub-core/normal/menu_entry.c +5
-2pos = linep->pos + (term_screen - screen->terms); -if (!*pos) - *pos =grub_calloc (linep->len +1 ,sizeof (**pos)); +if (*pos ==NULL ) + { + *pos =grub_calloc (linep->len +1 ,sizeof (**pos)); +if (*pos ==NULL ) +return ;Hi Sridhar,
Thank you so much for the patch!
Quoted 8 lines
In my opinion, returning due to
grub_callocfailure might not be a good idea here!To me, it seems
grub_print_ucs4_menu()and its corresponding functions which uses 'pos' as a last argument handles NULL properly. So returning based on this argument being NULL might not be a good idea. There are other parts of the code in GRUB wheregrub_print_ucs4_menu()has been called with this last argument as 0.
Yeah, I think Avnish is right.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel