nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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