mirror of
https://git.proxmox.com/git/grub2
synced 2025-10-04 23:21:32 +00:00
88 lines
2.2 KiB
Diff
88 lines
2.2 KiB
Diff
Description: Guard against scripts containing no commands
|
|
Make grub-script-check fail on scripts containing no commands, to guard
|
|
against corrupted grub-mkconfig setups that produce no useful output.
|
|
Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/5044
|
|
Author: Colin Watson <cjwatson@debian.org>
|
|
Bug-Debian: http://bugs.debian.org/713886
|
|
Forwarded: not-needed
|
|
Last-Update: 2013-06-25
|
|
|
|
Index: b/Makefile.util.def
|
|
===================================================================
|
|
--- a/Makefile.util.def
|
|
+++ b/Makefile.util.def
|
|
@@ -701,6 +701,12 @@
|
|
|
|
script = {
|
|
testcase;
|
|
+ name = grub_script_no_commands;
|
|
+ common = tests/grub_script_no_commands.in;
|
|
+};
|
|
+
|
|
+script = {
|
|
+ testcase;
|
|
name = partmap_test;
|
|
common = tests/partmap_test.in;
|
|
};
|
|
Index: b/tests/grub_script_no_commands.in
|
|
===================================================================
|
|
--- /dev/null
|
|
+++ b/tests/grub_script_no_commands.in
|
|
@@ -0,0 +1,21 @@
|
|
+#! /bin/sh
|
|
+set -e
|
|
+
|
|
+# grub-script-check refuses to pass a file with no commands; this usually
|
|
+# indicates a bug in the code generating that file.
|
|
+
|
|
+@builddir@/grub-script-check <<EOF && exit 1
|
|
+
|
|
+EOF
|
|
+
|
|
+@builddir@/grub-script-check <<EOF && exit 1
|
|
+# comment
|
|
+EOF
|
|
+
|
|
+@builddir@/grub-script-check <<EOF && exit 1
|
|
+# comment 1
|
|
+# comment 2
|
|
+
|
|
+EOF
|
|
+
|
|
+exit 0
|
|
Index: b/util/grub-script-check.c
|
|
===================================================================
|
|
--- a/util/grub-script-check.c
|
|
+++ b/util/grub-script-check.c
|
|
@@ -92,7 +92,7 @@
|
|
int lineno = 0;
|
|
FILE *file = 0;
|
|
struct arguments arguments;
|
|
- int found_input = 0;
|
|
+ int found_input = 0, found_cmd = 0;
|
|
struct grub_script *script = NULL;
|
|
|
|
auto grub_err_t get_config_line (char **line, int cont);
|
|
@@ -177,6 +177,8 @@
|
|
script = grub_script_parse (input, get_config_line);
|
|
if (script)
|
|
{
|
|
+ if (script->cmd)
|
|
+ found_cmd = 1;
|
|
grub_script_execute (script);
|
|
grub_script_free (script);
|
|
}
|
|
@@ -191,6 +193,12 @@
|
|
fprintf (stderr, _("Syntax error at line %u\n"), lineno);
|
|
return 1;
|
|
}
|
|
+ if (! found_cmd)
|
|
+ {
|
|
+ fprintf (stderr, _("Script contains no commands and will do nothing\n"),
|
|
+ ctx.arguments.filename);
|
|
+ return 1;
|
|
+ }
|
|
|
|
return 0;
|
|
}
|