* util/grub-script-check.c: Fail on scripts containing no
authorColin Watson <cjwatson@ubuntu.com>
Tue, 25 Jun 2013 14:08:11 +0000 (15:08 +0100)
committerColin Watson <cjwatson@ubuntu.com>
Tue, 25 Jun 2013 14:08:11 +0000 (15:08 +0100)
commands, to guard against corrupted grub-mkconfig setups that
produce no useful output.
* tests/grub_script_no_commands.in: New test.
* Makefile.util.def (grub_script_no_commands): Add.
Reported by Hans Putter.  Fixes Debian bug #713886.

ChangeLog
Makefile.util.def
tests/grub_script_no_commands.in [new file with mode: 0644]
util/grub-script-check.c

index cce65e8..0aae8df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-06-25  Colin Watson  <cjwatson@ubuntu.com>
+
+       * util/grub-script-check.c: Fail on scripts containing no
+       commands, to guard against corrupted grub-mkconfig setups that
+       produce no useful output.
+       * tests/grub_script_no_commands.in: New test.
+       * Makefile.util.def (grub_script_no_commands): Add.
+       Reported by Hans Putter.  Fixes Debian bug #713886.
+
 2013-06-16  Andrey Borzenkov <arvidjaar@gmail.com>
 
        * grub-core/disk/diskfilter.c: Forgot to remove comment
index 97abd84..0b9f56c 100644 (file)
@@ -748,6 +748,12 @@ script = {
   common = tests/grub_script_not.in;
 };
 
+script = {
+  testcase;
+  name = grub_script_no_commands;
+  common = tests/grub_script_no_commands.in;
+};
+
 script = {
   testcase;
   name = partmap_test;
diff --git a/tests/grub_script_no_commands.in b/tests/grub_script_no_commands.in
new file mode 100644 (file)
index 0000000..c31d267
--- /dev/null
@@ -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 48c772a..0d0a83c 100644 (file)
@@ -143,7 +143,7 @@ main (int argc, char *argv[])
     .file = 0
   };
   char *input;
-  int found_input = 0;
+  int found_input = 0, found_cmd = 0;
   struct grub_script *script = NULL;
 
   set_program_name (argv[0]);
@@ -188,6 +188,8 @@ main (int argc, char *argv[])
       script = grub_script_parse (input, get_config_line, &ctx);
       if (script)
        {
+         if (script->cmd)
+           found_cmd = 1;
          grub_script_execute (script);
          grub_script_free (script);
        }
@@ -202,6 +204,12 @@ main (int argc, char *argv[])
       fprintf (stderr, _("Syntax error at line %u\n"), ctx.lineno);
       return 1;
     }
+  if (! found_cmd)
+    {
+      fprintf (stderr, _("Script contains no commands and will do nothing\n"),
+              ctx.arguments.filename);
+      return 1;
+    }
 
   return 0;
 }