From: Sean Anderson Date: Sun, 28 Feb 2021 18:51:53 -0500 Subject: [PATCH] hush: Fix assignments being misinterpreted as commands In-Reply-To: <914D3972-B8A7-45A8-AC3E-95519C56EEB7@gmx.de> References: <20210228212951.1175231-1-seanga2@gmail.com> <914D3972-B8A7-45A8-AC3E-95519C56EEB7@gmx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 2/28/21 6:40 PM, Heinrich Schuchardt wrote: > Am 28. Februar 2021 22:29:51 MEZ schrieb Sean Anderson : >> 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 > > The commit message does not explain why this patch is needed. This is a bug I noticed while writing some tests of hush. > What shall be the value off foo after this line? It should be bar. This is an existing difference when compared with bash. For example, without this patch, we have => foo=bar echo $foo bar => echo $foo bar > > What will be the output of > > foo=bar echo ${foo} > > with and without yor patch? It is the same. --Sean > > Best regards > > Heinrich > > >> Unknown command 'foo=bar' - try 'help' >> >> Signed-off-by: Sean Anderson >> --- >> >> common/cli_hush.c | 2 +- >> test/cmd/test_echo.c | 2 ++ >> 2 files changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/common/cli_hush.c b/common/cli_hush.c >> index b7f0f0ff41..1b9bef64b6 100644 >> --- a/common/cli_hush.c >> +++ b/common/cli_hush.c >> @@ -1672,7 +1672,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 >> } >> diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c >> index 4183cf75bb..13e1fb7c82 100644 >> --- a/test/cmd/test_echo.c >> +++ b/test/cmd/test_echo.c >> @@ -33,6 +33,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, "}, >