Skip to contentSkip to conversation

script/execute: Add NULL check for grub_calloc in gettext_append

PATCH In review Sridhar Markonda 2 participants 2 messages Dec 2, 2025 – Dec 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 script/execute: Add NULL check for grub_calloc in gettext_append

Add a NULL check after grub_calloc in gettext_append to handle allocation errors. This prevents using a NULL pointer and stops crashes during string translation.

---
 grub-core/script/execute.c | 2 ++
 1 file changed, 2 insertions(+)
grub-core/script/execute.c +2 -0
index 62afcdc99..369d985ee 100644
@@ -562,6 +562,8 @@ gettext_append (struct grub_script_argv *result, const char *orig_str)
     if (*iptr == '$')
       dollar_cnt++;
   ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0]));
+  if (ctx.allowed_strings == NULL)
+    goto fail;
 
   if (parse_string (orig_str, gettext_save_allow, &ctx, 0))
     goto fail;
Signature · 7 lines
2.47.3


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

Add a NULL check after grub_calloc in gettext_append to handle allocation errors. This prevents using a NULL pointer and stops crashes during string translation.

Daniel

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