]> git.ipfire.org Git - thirdparty/grub.git/commit
script/execute: Avoid crash when using "$#" outside a function scope
authorDaniel Axtens <dja@axtens.net>
Mon, 11 Jan 2021 06:30:42 +0000 (17:30 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:17 +0000 (15:54 +0100)
commitfe0586347ee46f927ae27bb9673532da9f5dead5
treea2d330a3917f4de5bbc5eb95351aea722913dad3
parent6afbe6063c95b827372f9ec310c9fc7461311eb1
script/execute: Avoid crash when using "$#" outside a function scope

"$#" represents the number of arguments to a function. It is only
defined in a function scope, where "scope" is non-NULL. Currently,
if we attempt to evaluate "$#" outside a function scope, "scope" will
be NULL and we will crash with a NULL pointer dereference.

Do not attempt to count arguments for "$#" if "scope" is NULL. This
will result in "$#" being interpreted as an empty string if evaluated
outside a function scope.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/script/execute.c