From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Warren Date: Sat, 01 Mar 2014 21:26:26 -0700 Subject: [U-Boot] [PATCH V2] hush: fix some quoted variable expansion issues In-Reply-To: References: <1393563654-16490-1-git-send-email-swarren@wwwdotorg.org> Message-ID: <5312B2F2.1070000@wwwdotorg.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 03/01/2014 05:10 PM, Simon Glass wrote: > Hi Stephen, > > On 27 February 2014 22:00, Stephen Warren > wrote: > > 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}<<" > > > Is there an upstream still for hush, or are we so far away that it > doesn't matter? If there is, was this bug fixed there? Well, the comments at the head of the file say it came from Busybox, but it's obviously diverged massively since it was imported: $ wc -l busybox/shell/hush.c u-boot/common/hush.c 9156 busybox/shell/hush.c 3682 u-boot/common/hush.c $ diff -u busybox/shell/hush.c u-boot/common/hush.c|wc -l 12264 Also, the function this patch touches doesn't seem to exist under that name any more. From a quick look at the source, I couldn't tell what the equivalent is. Perhaps replaying patches to that file in Busybox since the fork might be more useful. A quick Google search for "hush" or "hush shell" doesn't seem to yield any other alternative upstreams. > diff --git a/common/hush.c b/common/hush.c > index 3f3a79c..66ece41 100644 > --- a/common/hush.c > +++ b/common/hush.c > @@ -221,6 +221,7 @@ struct child_prog { > pid_t pid; /* 0 if > exited */ > #endif > char **argv; /* program name and > arguments */ > + int *argv_nonnull; > > > This could do with a comment. I did wonder if I should name this "quoted". I'd originally shied away from this to prevent changing the terminology, but since hush.c has diverged so much, perhaps that wouldn't be an issue...