]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
bootstd: Handle a few special cases in cmdline_set_arg()
authorSimon Glass <sjg@chromium.org>
Tue, 24 Oct 2023 18:17:36 +0000 (07:17 +1300)
committerTom Rini <trini@konsulko.com>
Wed, 1 Nov 2023 16:26:44 +0000 (12:26 -0400)
Two bugs have appeared:

- arguments can have an equals sign embedded in them, which must be
  considered part of the value
- arguments must fully match the name; partial matches should be
  ignored

Fix these and add a test to cover both.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootflow.c
test/boot/bootflow.c

index be543c8588cc99e235fac670857d8e19651148e4..6922e7e0c4e753760215f77e101e110c6bad1d31 100644 (file)
@@ -752,7 +752,7 @@ int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
                                        in_quote = false;
                                continue;
                        }
-                       if (*p == '=') {
+                       if (*p == '=' && !arg_end) {
                                arg_end = p;
                                val = p + 1;
                        } else if (*p == '"') {
@@ -788,7 +788,8 @@ int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
                }
 
                /* if this is the target arg, update it */
-               if (!strncmp(from, set_arg, arg_end - from)) {
+               if (arg_end - from == set_arg_len &&
+                   !strncmp(from, set_arg, set_arg_len)) {
                        if (!buf) {
                                bool has_quote = val_end[-1] == '"';
 
index f5b2059140acae8f5a9d463ebf99b9c3462e3106..f640db8a24184213fd14106e4b8f7452b1f44ec7 100644 (file)
@@ -973,6 +973,26 @@ static int bootflow_cmdline(struct unit_test_state *uts)
 }
 BOOTSTD_TEST(bootflow_cmdline, 0);
 
+/* test a few special changes to a long command line */
+static int bootflow_cmdline_special(struct unit_test_state *uts)
+{
+       char buf[500];
+       int pos;
+
+       /*
+        * check handling of an argument which has an embedded '=', as well as
+        * handling of a argument which partially matches ("ro" and "root")
+        */
+       ut_asserteq(32, cmdline_set_arg(
+               buf, sizeof(buf),
+               "loglevel=7 root=PARTUUID=d68352e3 rootwait ro noinitrd",
+               "root", NULL, &pos));
+       ut_asserteq_str("loglevel=7 rootwait ro noinitrd", buf);
+
+       return 0;
+}
+BOOTSTD_TEST(bootflow_cmdline_special, 0);
+
 /* Test ChromiumOS bootmeth */
 static int bootflow_cros(struct unit_test_state *uts)
 {