]> git.ozlabs.org Git - petitboot/commitdiff
discover/syslinux-parser: consistent cmdline arg processing
authorBrett Grandbois <brett.grandbois@opengear.com>
Sun, 10 Jun 2018 21:54:08 +0000 (07:54 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 12 Jun 2018 04:43:36 +0000 (14:43 +1000)
In signed-boot environments consistent handling of kernel commandline
options is essential as they must be pre-signed.  In the syslinux parser
ensure that in the absence of a global APPEND they are processed
exactly as found and not with the leading space that the current APPEND
processing has as a shortcut.

Signed-off-by: Brett Grandbois <brett.grandbois@opengear.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/syslinux-parser.c
test/parser/test-syslinux-explicit.c
test/parser/test-syslinux-global-append.c
test/parser/test-syslinux-single-yocto.c

index c611ac92b794e878a87d4793d9557df2243abe9e..defafd261494de3fc62910e513bf024f2bde7c05 100644 (file)
@@ -338,11 +338,13 @@ static void syslinux_finalize(struct conf_context *conf)
                        /* '-' can signal do not use global APPEND */
                        if (!strcmp(syslinux_opt->append, "-"))
                                opt->boot_args = talloc_strdup(opt, "");
-                       else
+                       else if (global_append)
                                opt->boot_args = talloc_asprintf(opt, "%s %s",
                                                                 global_append,
                                                                 syslinux_opt->append);
-               } else
+                       else
+                               opt->boot_args = talloc_strdup(opt, syslinux_opt->append);
+               } else if (global_append)
                        opt->boot_args = talloc_strdup(opt, global_append);
 
                if (!opt->boot_args)
@@ -455,13 +457,10 @@ static int syslinux_parse(struct discover_context *dc)
        /*
         * set the global defaults
         * by spec 'default' defaults to 'linux' and
-        * 'implicit' defaults to '1', we also just set
-        * and empty string in 'append' to make it easier
-        * in syslinux_finish
+        * 'implicit' defaults to '1'
         */
        conf_set_global_option(conf, "default", "linux");
        conf_set_global_option(conf, "implicit", "1");
-       conf_set_global_option(conf, "append", "");
 
        for (filename = syslinux_conf_files; *filename; filename++) {
                /*
index 5d23f50001b60b7235235ed719872254eef909ea..82030bf72c2df3ea0f302e9b93f05a732500f3b1 100644 (file)
@@ -36,6 +36,6 @@ void run_test(struct parser_test *test)
 
        check_name(opt, "backup");
        check_resolved_local_resource(opt->boot_image, ctx->device, "/backup/vmlinuz");
-       check_args(opt, " root=/dev/sdb");
+       check_args(opt, "root=/dev/sdb");
        check_resolved_local_resource(opt->initrd, ctx->device, "/boot/initrd");
 }
index 18af99ae76756222fb7b005e52545e3037818cab..af2e9affc20b8077c189199a7e4114f3e1d326f7 100644 (file)
@@ -18,6 +18,9 @@ LABEL hyphen
 KERNEL /test/vmlinuz
 APPEND -
 
+LABEL onlyglobal
+KERNEL /only/vmlinuz
+
 #endif
 
 void run_test(struct parser_test *test)
@@ -31,8 +34,9 @@ void run_test(struct parser_test *test)
 
        ctx = test->ctx;
 
-       check_boot_option_count(ctx, 3);
-       opt = get_boot_option(ctx, 2);
+       check_boot_option_count(ctx, 4);
+
+       opt = get_boot_option(ctx, 3);
 
        check_name(opt, "linux");
        check_resolved_local_resource(opt->boot_image, ctx->device, "/vmlinuz");
@@ -40,17 +44,24 @@ void run_test(struct parser_test *test)
        check_args(opt, "console=ttyS0 console=tty0");
        check_not_present_resource(opt->initrd);
 
-       opt = get_boot_option(ctx, 1);
+       opt = get_boot_option(ctx, 2);
 
        check_name(opt, "backup");
        check_resolved_local_resource(opt->boot_image, ctx->device, "/backup/vmlinuz");
        check_args(opt, "console=ttyS0 root=/dev/sdb");
        check_resolved_local_resource(opt->initrd, ctx->device, "/boot/initrd");
 
-       opt = get_boot_option(ctx, 0);
+       opt = get_boot_option(ctx, 1);
 
        check_name(opt, "hyphen");
        check_resolved_local_resource(opt->boot_image, ctx->device, "/test/vmlinuz");
        check_args(opt, "");
        check_not_present_resource(opt->initrd);
+
+       opt = get_boot_option(ctx, 0);
+
+       check_name(opt, "onlyglobal");
+       check_resolved_local_resource(opt->boot_image, ctx->device, "/only/vmlinuz");
+       check_args(opt, "console=ttyS0");
+       check_not_present_resource(opt->initrd);
 }
index e5e084d2869a4d81d8c8cbec41c029762f657910..dd265772d4a58c13ef6cd4e8582bb745636d518d 100644 (file)
@@ -32,5 +32,5 @@ void run_test(struct parser_test *test)
        check_name(opt, "boot");
        check_resolved_local_resource(opt->boot_image, ctx->device, "/vmlinuz");
        check_is_default(opt);
-       check_args(opt, " console=ttyS0,115200n8 console=tty0");
+       check_args(opt, "console=ttyS0,115200n8 console=tty0");
 }