From: Lidong Chen Date: Wed, 29 Jan 2025 06:48:37 +0000 (+0000) Subject: script/execute: Fix potential underflow and NULL dereference X-Git-Tag: archive/raspbian/2.12-8+rpi1^2~13 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bd73b94d3f5589052710068c54ccd4c664b2bd49;p=grub2.git script/execute: Fix potential underflow and NULL dereference The result is initialized to 0 in grub_script_arglist_to_argv(). If the for loop condition is not met both result.args and result.argc remain 0 causing result.argc - 1 to underflow and/or result.args NULL dereference. Fix the issues by adding relevant checks. Fixes: CID 473880 Signed-off-by: Lidong Chen Reviewed-by: Daniel Kiper Gbp-Pq: Topic cve-2025-jan Gbp-Pq: Name script-execute-Fix-potential-underflow-and-NULL-dereferen.patch --- diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index e1450f4..a86e005 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -760,6 +760,9 @@ cleanup: } } + if (result.args == NULL || result.argc == 0) + goto fail; + if (! result.args[result.argc - 1]) result.argc--;