nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0376-script-execute-Don-t-crash-on-a-for-loop-with-no-ite.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Fri, 22 Jan 2021 16:18:26 +1100
9723a8
Subject: [PATCH] script/execute: Don't crash on a "for" loop with no items
9723a8
9723a8
The following crashes the parser:
9723a8
9723a8
  for x in; do
9723a8
  0
9723a8
  done
9723a8
9723a8
This is because grub_script_arglist_to_argv() doesn't consider the
9723a8
possibility that arglist is NULL. Catch that explicitly.
9723a8
9723a8
This avoids a NULL pointer dereference.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/script/execute.c | 3 +++
9723a8
 1 file changed, 3 insertions(+)
9723a8
9723a8
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
9723a8
index 17f4dcab2c6..266d99ed337 100644
9723a8
--- a/grub-core/script/execute.c
9723a8
+++ b/grub-core/script/execute.c
9723a8
@@ -658,6 +658,9 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
9723a8
   struct grub_script_arg *arg = 0;
9723a8
   struct grub_script_argv result = { 0, 0, 0 };
9723a8
 
9723a8
+  if (arglist == NULL)
9723a8
+    return 1;
9723a8
+
9723a8
   for (; arglist && arglist->arg; arglist = arglist->next)
9723a8
     {
9723a8
       if (grub_script_argv_next (&result))