busybox/shell/ash_test/ash-vars/var_leak.tests

22 lines
540 B
Plaintext
Raw Normal View History

# cat is an external program, variable should not leak out of it.
# this currently fails with CONFIG_FEATURE_SH_NOFORK=y
VAR=''
VAR=val0 cat /dev/null
echo "should be empty: '$VAR'"
# true is a regular builtin, variable should not leak out of it.
VAR=''
VAR=val1 true
echo "should be empty: '$VAR'"
# ash follows the "special builtin leaks variables" rule here:
# exec is a special builtin. (bash does not do it)
VAR=''
VAR=val2 exec 2>&1
echo "should be not empty: '$VAR'"
f() { true; }
VAR=''
VAR=val3 f
ash: eval: Variable assignments on functions are no longer persistent Upstream commit: Date: Wed, 4 Apr 2018 17:54:01 +0800 eval: Variable assignments on functions are no longer persistent Dirk Fieldhouse <fieldhouse@gmx.net> wrote: > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open > Group Technical Standard Base Specifications, Issue 7") > <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>, > we read under '2.9.1 Simple Commands' > > "Variable assignments shall be performed as follows: > ... > - If the command name is a standard utility implemented as a function > (see XBD Utility), the effect of variable assignments shall be as if the > utility was not implemented as a function. > ... > - If the command name is a function that is not a standard utility > implemented as a function, variable assignments shall affect the current > execution environment during the execution of the function. It is > unspecified: > > * Whether or not the variable assignments persist after the > completion of the function > > * Whether or not the variables gain the export attribute during > the execution of the function > > * Whether or not export attributes gained as a result of the > variable assignments persist after the completion of the function (if > variable assignments persist after the completion of the function)" POSIX used to require the current dash behaviour. However, you're right that this is no longer the case. This patch will remove the persistence of the variable assignment. I have considered the exporting the variables during the function execution but have decided against it because: 1) It makes the code bigger. 2) dash has never done this in the past. 3) You cannot use this portably anyway. Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta evalcommand 1606 1635 +29 evalcase 313 317 +4 evalfun 280 268 -12 pushlocalvars 48 - -48 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/1 up/down: 33/-60) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05 14:09:18 +05:30
echo "should be empty: '$VAR'"