Skip to content

Commit 442b676

Browse files
committed
script/execute: Don't let trailing blank lines determine the return code
grub_script_execute_sourcecode() parses and executes code one line at a time, updating the return code each time because only the last line determines the final status. However, trailing new lines were also executed, masking any failure on the previous line. Fix this by only trying to execute the command when there is actually one present. This has presumably never been noticed because this code is not used by regular functions, only in special cases like eval and menu entries. The latter generally don't return at all, having booted an OS. When failing to boot, upstream GRUB triggers the fallback mechanism regardless of the return code. We noticed the problem while using Red Hat's patches, which change this behaviour to take account of the return code. In that case, a failure takes you back to the menu rather than triggering a fallback. Signed-off-by: James Le Cuirot <[email protected]>
1 parent 1f2af45 commit 442b676

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

grub-core/script/execute.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,10 @@ grub_script_execute_sourcecode (const char *source)
935935
break;
936936
}
937937

938-
ret = grub_script_execute (parsed_script);
938+
/* Don't let trailing blank lines determine the return code. */
939+
if (parsed_script->cmd)
940+
ret = grub_script_execute (parsed_script);
941+
939942
grub_script_free (parsed_script);
940943
grub_free (line);
941944
}

tests/grub_script_eval.in

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
eval echo "Hello world"
44
valname=tst
55
eval $valname=hi
6-
echo $tst
6+
echo $tst
7+
8+
if eval "
9+
false
10+
"; then
11+
echo should have failed
12+
else
13+
echo failed as expected
14+
fi

0 commit comments

Comments
 (0)