discover/pxe: check for a valid boot option before adding
authorJeremy Kerr <jk@ozlabs.org>
Fri, 6 Sep 2013 03:46:56 +0000 (11:46 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 6 Sep 2013 05:23:35 +0000 (13:23 +0800)
If we didn't find any valid boot options in the pxe buffer, we'll call
discover_context_add_boot_option with a NULL boot option.

This change adds a check before we try to add the boot option, and a
test to verify this situation.

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

index 1f6eb0f0bbc8d3458188a1392f68ddbad549c126..ca0f4b543ef09a6bbc9e4a4eb0db0680e8d96154 100644 (file)
@@ -12,7 +12,8 @@
 
 static void pxe_finish(struct conf_context *conf)
 {
 
 static void pxe_finish(struct conf_context *conf)
 {
-       discover_context_add_boot_option(conf->dc, conf->parser_info);
+       if (conf->parser_info)
+               discover_context_add_boot_option(conf->dc, conf->parser_info);
 }
 
 static void pxe_process_pair(struct conf_context *ctx,
 }
 
 static void pxe_process_pair(struct conf_context *ctx,
index 9029544a4a7d3d7170edd0653864149d9317c22f..e221bf2080c1918084ad92e59ec77badc980be5f 100644 (file)
@@ -41,6 +41,7 @@ TESTS = \
        test-yaboot-device-override \
        test-yaboot-default \
        test-yaboot-rh8-ppc64 \
        test-yaboot-device-override \
        test-yaboot-default \
        test-yaboot-rh8-ppc64 \
+       test-pxe-empty \
        test-pxe-single \
        test-pxe-initrd-in-append
 
        test-pxe-single \
        test-pxe-initrd-in-append
 
diff --git a/test/parser/test-pxe-empty.c b/test/parser/test-pxe-empty.c
new file mode 100644 (file)
index 0000000..eb3b758
--- /dev/null
@@ -0,0 +1,19 @@
+
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+
+#endif
+
+void run_test(struct parser_test *test)
+{
+       struct discover_context *ctx;
+
+       test_read_conf_embedded(test);
+       test_set_conf_source(test, "tftp://host/dir/conf.txt");
+       test_run_parser(test, "pxe");
+
+       ctx = test->ctx;
+
+       check_boot_option_count(ctx, 0);
+}