]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
hush: Fix assignments being misinterpreted as commands
authorSean Anderson <seanga2@gmail.com>
Sun, 28 Feb 2021 21:29:51 +0000 (16:29 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 12 Apr 2021 21:17:11 +0000 (17:17 -0400)
If there were no variable substitutions in a command, then initial
assignments would be misinterpreted as commands, instead of being skipped
over. This is demonstrated by the following example:

=> foo=bar echo baz
Unknown command 'foo=bar' - try 'help'

Signed-off-by: Sean Anderson <seanga2@gmail.com>
common/cli_hush.c
test/cmd/test_echo.c

index 9466651d1a2cb55b8768811320118dbc03fa4716..6cff3b1185024fd82bfc6d381eff236f7b3f377f 100644 (file)
@@ -1673,7 +1673,7 @@ static int run_pipe_real(struct pipe *pi)
                        return -1;
                }
                /* Process the command */
-               return cmd_process(flag, child->argc, child->argv,
+               return cmd_process(flag, child->argc - i, child->argv + i,
                                   &flag_repeat, NULL);
 #endif
        }
index 9d60d7d1a0bd84f069519307d57912471e1948f1..091e4f823c9081605ff27cf11029d0cb9fe90a70 100644 (file)
@@ -34,6 +34,8 @@ static struct test_data echo_data[] = {
         */
        {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx",
         "a) X b) ${jQx} c) X"},
+       /* Test shell variable assignments without substitutions */
+       {"foo=bar echo baz", "baz"},
        /* Test handling of shell variables. */
        {"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;",
         "1, 2, 3, "},