Skip to contentSkip to conversation

normal/menu_entry: Add grub_calloc failure check

PATCH Superseded Sridhar Markonda 3 participants 3 messages Dec 1, 2025 – Dec 2, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 normal/menu_entry: Add grub_calloc failure check

Add a NULL check to prevent failure from grub_calloc in update_screen. This stops possible NULL pointer dereference and avoids unexpected behavior.

---
 grub-core/normal/menu_entry.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
grub-core/normal/menu_entry.c +5 -1
index 8b0d17e3f..dfba20cb9 100644
@@ -296,7 +296,11 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
 	  pos = linep->pos + (term_screen - screen->terms);
 
 	  if (!*pos)
-	    *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+	    { 
+	      *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+	      if (!*pos)
+		return;
+	    }
 
 	  if (i == region_start || linep == screen->lines + screen->line
 	      || (i > region_start && mode == ALL_LINES))
Signature · 7 lines
2.47.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 13 lines · Sridhar Markonda

Add a NULL check to prevent failure from grub_calloc in update_screen. This stops possible NULL pointer dereference and avoids unexpected behavior.

---
 grub-core/normal/menu_entry.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
grub-core/normal/menu_entry.c +0 -0
index 8b0d17e3f..dfba20cb9 100644

grub-core/normal/menu_entry.c update_screen (struct screen *screen, struct per_term_screen *term_screen, · line 301

Quoted 7 lines
grub-core/normal/menu_entry.c +3 -1
@@ -296,7 +296,11 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
 	  pos = linep->pos + (term_screen - screen->terms);
 
 	  if (!*pos)
-	    *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+	    {
+	      *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+	      if (!*pos)

s/if (!*pos)/if (*pos != NULL)/

I'd also recommend changing it above as well. Everything else in the patch LGTM!

Alec Brown

Quoted 7 lines
grub-core/normal/menu_entry.c +2 -1
+		return;
+	    }
 
 	  if (i == region_start || linep == screen->lines + screen->line
 	      || (i > region_start && mode == ALL_LINES))
--

2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
In reply to Sridhar Markonda
Quoted 17 lines · Sridhar Markonda

Add a NULL check to prevent failure from grub_calloc in update_screen. This stops possible NULL pointer dereference and avoids unexpected behavior.

---
grub-core/normal/menu_entry.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
grub-core/normal/menu_entry.c +0 -0
index 8b0d17e3f..dfba20cb9 100644

grub-core/normal/menu_entry.c update_screen (struct screen *screen, struct per_term_screen *term_screen, · line 301

Quoted 7 lines
grub-core/normal/menu_entry.c +3 -1
@@ -296,7 +296,11 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
 pos = linep->pos + (term_screen - screen->terms);
 
 if (!*pos)
-    *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+    { 
+      *pos = grub_calloc (linep->len + 1, sizeof (**pos));
+      if (!*pos)

use if (*pos == NULL) instead of if (!*pos)

Thanks,
Sudhakar

Quoted 8 lines
grub-core/normal/menu_entry.c +2 -0
+        return;
+    }
 
 if (i == region_start || linep == screen->lines + screen->line
     || (i > region_start && mode == ALL_LINES))
Signature · 1 line
2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel