From: Jeremy Kerr Date: Tue, 10 Dec 2013 00:54:17 +0000 (+0800) Subject: discover/yaboot: Fix assertion failure on empty yaboot files X-Git-Tag: v1.0.0~289 X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=32e2eac76dcdc7b54454c9f3731496f8947cdbbc discover/yaboot: Fix assertion failure on empty yaboot files 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 --- diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index e52187f..f16ac72 100644 --- a/discover/yaboot-parser.c +++ b/discover/yaboot-parser.c @@ -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); diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 46f87ce..abc95bb 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -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 index 0000000..00d08ad --- /dev/null +++ b/test/parser/test-yaboot-empty.c @@ -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); +}