]> git.sur5r.net Git - u-boot/commit
hush: fix some quoted variable expansion issues
authorStephen Warren <swarren@wwwdotorg.org>
Sun, 2 Mar 2014 05:16:10 +0000 (22:16 -0700)
committerTom Rini <trini@ti.com>
Fri, 7 Mar 2014 15:59:06 +0000 (10:59 -0500)
commitfe9ca3d3287185e388de55904420cc7915e4a3b1
tree6ba29043f99cae9161808aa600da28f145029f91
parenteebd1b58d05aa3719aa23be3e4a5c1424b26ff11
hush: fix some quoted variable expansion issues

The following shell command fails:

if test -z "$x"; then echo "zero"; else echo "non-zero"; fi

(assuming $x does not exist, it prints "non-zero" rather than "zero").

... since "$x" expands to nothing, and the argument is completely
dropped, causing too few to be passed to -z, causing cmd_test() to
error out early.

This is because when variable expansions are processed by make_string(),
the expanded results are concatenated back into a new string. However,
no quoting is applied when doing so, so any empty variables simply don't
generate any parameter when the combined string is parsed again.

Fix this by explicitly replacing quoting any argument that was originally
quoted when re-generating a string from the already-parsed argument list.

This also fixes loss of whitespace in commands such as:

setenv space " "
setenv var " 1${space}${space} 2 "
echo ">>${var}<<"

Reported-by: Russell King <linux@arm.linux.org.uk>
Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
common/hush.c
test/command_ut.c