]> git.ozlabs.org Git - petitboot/commitdiff
discover/yaboot: Fix assertion failure on empty yaboot files
authorJeremy Kerr <jk@ozlabs.org>
Tue, 10 Dec 2013 00:54:17 +0000 (08:54 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 10 Dec 2013 01:03:43 +0000 (09:03 +0800)
yaboot configuration files with no option will cause an assertion
failure (or segfault), as we unconditionally call yaboot_finish().

Check for the presence of an option in yaboot_finish() instead of
asserting.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/yaboot-parser.c
test/parser/Makefile.am
test/parser/test-yaboot-empty.c [new file with mode: 0644]

index e52187fff6b61203325e13019fa472ca95c9ad0f..f16ac723ff4b7a7f672616d9bd7c96efd9eadb1a 100644 (file)
@@ -102,7 +102,8 @@ static void yaboot_finish(struct conf_context *conf)
        const char *default_label;
        struct boot_option *opt;
 
-       assert(state->opt);
+       if (!state->opt)
+               return;
 
        opt = state->opt->option;
        assert(opt);
index 46f87cecdabd01d6f31b5d9ba26f06bf7241e57a..abc95bbd98e6d2c4d39f00289f89c53572560564 100644 (file)
@@ -42,6 +42,7 @@ TESTS = \
        test-grub2-lexer-error \
        test-grub2-parser-error \
        test-kboot-single \
+       test-yaboot-empty \
        test-yaboot-single \
        test-yaboot-partition \
        test-yaboot-partition-override \
diff --git a/test/parser/test-yaboot-empty.c b/test/parser/test-yaboot-empty.c
new file mode 100644 (file)
index 0000000..00d08ad
--- /dev/null
@@ -0,0 +1,12 @@
+#include "parser-test.h"
+
+static const char empty[] = "";
+
+void run_test(struct parser_test *test)
+{
+       test_read_conf_data(test, "/etc/yaboot.conf", empty);
+
+       test_run_parser(test, "yaboot");
+
+       check_boot_option_count(test->ctx, 0);
+}