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 <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Lidong Chen 2025-01-29 06:48:37 +00:00 committed by Daniel Kiper
parent e3c578a56f
commit d13b6e8ebd

View File

@ -760,6 +760,9 @@ cleanup:
}
}
if (result.args == NULL || result.argc == 0)
goto fail;
if (! result.args[result.argc - 1])
result.argc--;