nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0429-script-execute-Avoid-crash-when-using-outside-a-func.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Axtens <dja@axtens.net>
80913e
Date: Mon, 11 Jan 2021 17:30:42 +1100
80913e
Subject: [PATCH] script/execute: Avoid crash when using "$#" outside a
80913e
 function scope
80913e
80913e
"$#" represents the number of arguments to a function. It is only
80913e
defined in a function scope, where "scope" is non-NULL. Currently,
80913e
if we attempt to evaluate "$#" outside a function scope, "scope" will
80913e
be NULL and we will crash with a NULL pointer dereference.
80913e
80913e
Do not attempt to count arguments for "$#" if "scope" is NULL. This
80913e
will result in "$#" being interpreted as an empty string if evaluated
80913e
outside a function scope.
80913e
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/script/execute.c | 2 +-
80913e
 1 file changed, 1 insertion(+), 1 deletion(-)
80913e
80913e
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
80913e
index 2e47c046741..17f4dcab2c6 100644
80913e
--- a/grub-core/script/execute.c
80913e
+++ b/grub-core/script/execute.c
80913e
@@ -519,7 +519,7 @@ gettext_putvar (const char *str, grub_size_t len,
80913e
     return 0;
80913e
 
80913e
   /* Enough for any number.  */
80913e
-  if (len == 1 && str[0] == '#')
80913e
+  if (len == 1 && str[0] == '#' && scope != NULL)
80913e
     {
80913e
       grub_snprintf (*ptr, 30, "%u", scope->argv.argc);
80913e
       *ptr += grub_strlen (*ptr);