NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/50834 (/bin/sh incorrectly treats ${unset_or_null_var:-} as '')



The following reply was made to PR bin/50834; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: bin/50834 (/bin/sh incorrectly treats ${unset_or_null_var:-} as '')
Date: Sat, 05 Mar 2016 12:59:15 +0700

 I tried to send this message (a message like this) soon after the previous
 one - it arrived at NetBSD's mailer, but after that, no idea (maybe I
 made a typo in the addresses somewhere).
 
 The point was that in the previous message, I reversed the test
 cases, $@"" is the one that works, and ""$@ is the one that doesn't.
 
 The cause turns out to be the output format of the parser in the
 shell - the parser appears to process everything correctly, but the
 output is "quoted" var @ or var @ "quoted" (with a null string, ie: nothing,
 after "quoted" in both cases.)   The problem is that "$@" also produces
 "quoted" var @.   Here the "var @" is the operand of "quoted".  That one
 is a very special case, if $@ is empty, the "$@" simply vanishes when it
 is evaluated.  Since the evaluation routine cannot tell the difference
 between ""$@ and "$@" because they look just the same in the intermediate
 form, ""$@ also vanishes when $@ is empty.
 
 The intermediate form has an "endquote" operator, but it is used rarely.
 I suspect that the fix for this is going to have it used more frequently.
 
 And after all this, this problem turns out to have nothing to do with the
 subject of the PR, which doesn't involve quotes at all (if quotes were
 present, anywhere that is legal according to the syntax, a null string would
 be the correct result.)   I am getting a handle on that bug as well, but it
 turns out to be a devious one to locate...   I know I said in the PR that
 I didn't think I would bother looking, as ${N} and ${N-} both produce the
 same output, so the form with the '-' seems useless - but it was pointed
 out to me that the ${N-} form is the correct way to refer to a variable that
 might be unset, if it is possible that the -u (nounset) might be set.
 ${N} would generate an error, ${N-} produces the same output, regardless
 of the value of the nounset option.  So, this form is not as useless as I
 expected.   It helps that FreeBSD's shell (which shares much of its history
 with ours) has these bugs fixed - but they have changed so much more than
 we have, that finding just what fixed it is not trivial.   They also have
 bugs that we don't (any more) so simply using their code is also not the
 best solution.
 
 kre
 


Home | Main Index | Thread Index | Old Index