summaryrefslogtreecommitdiff
path: root/shell/hush_test
AgeCommit message (Collapse)Author
2023-06-16shell/math: fix ?: to not evaluate not-taken branchesDenys Vlasenko
This fixes ash-arith-arith-ternary1/2.tests function old new delta evaluate_string 1271 1432 +161 arith_apply 968 1000 +32 arith 22 36 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0) Total: 207 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: fix order of expansion of variables to numbersDenys Vlasenko
This fixes arith-assign-in-varexp1.tests function old new delta evaluate_string 1132 1258 +126 arith_lookup_val 143 - -143 arith_apply 1132 977 -155 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298) Total: -172 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: remove special code to handle a?b?c:d:e, it works without it nowDenys Vlasenko
The "hack" to virtually parenthesize ? EXPR : made this unnecessary. The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated before continuing with the second : function old new delta evaluate_string 1148 1132 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: fix parsing of ?: and explain why it's parsed that wayDenys Vlasenko
This fixes arith-precedence1.tests. This breaks arith-ternary2.tests again (we now evaluate variables on not-taken branches). We need a better logic here anyway: not only bare variables should not evaluate when not-taken: 1 ? eval_me : do_not_eval but any (arbitrarily complex) expressions shouldn't evaluate as well! 1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4)) function old new delta evaluate_string 1097 1148 +51 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14shell: sync ash/hush test scriptsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14shell/math: fix the order of variable resolution in binopsDenys Vlasenko
function old new delta arith_apply 1134 1143 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-12hush: fix expansion of space in "a=${a:+$a }c" constructDenys Vlasenko
function old new delta encode_then_append_var_plusminus 554 552 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-25hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571Denys Vlasenko
function old new delta run_list 1012 1024 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-04-13hush: quote variable values printed by "set" (match ash behavior)Denys Vlasenko
function old new delta builtin_set 258 301 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-08-02ash: fix ifs cleanup on error pathsDenys Vlasenko
Patch by Alex Gorinson <algore3698@gmail.com> function old new delta evalvar 477 495 +18 varvalue 603 618 +15 subevalvar 1557 1572 +15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 48/0) Total: 48 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01ash: don't read past end of var in subvareval for bash substitutionsSören Tempel
Without this patch, BusyBox handles bash pattern substitutions without a terminating '/' character incorrectly. Consider the following shell script: _bootstrapver=5.0.211-r0 _referencesdir="/usr/${_bootstrapver/-*}/Sources" echo $_referencesdir This should output `/usr/5.0.211/Sources`. However, without this patch it instead outputs `/usr/5.0.211Sources`. This is due to the fact that BusyBox expects the bash pattern substitutions to always be terminated with a '/' (at least in this part of subvareval) and thus reads passed the substitution itself and consumes the '/' character which is part of the literal string. If there is no '/' after the substitution then BusyBox might perform an out-of-bounds read under certain circumstances. When replacing the bash pattern substitution with `${_bootstrapver/-*/}`, or with this patch applied, ash outputs the correct value. Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-11shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=yDenys Vlasenko
function old new delta re_execed_comm - 46 +46 main 72 86 +14 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-26shell: fix parsing of $(( (v)++ + NUM ))Denys Vlasenko
function old new delta evaluate_string 988 1011 +23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25shell: enable more tests which are passing nowDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-25shell: fix arithmentic evaluation of "++7" and such (it is + + 7, i.e. 7)Denys Vlasenko
function old new delta evaluate_string 945 988 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07ash: LINENO starts from 0 in -c SCRIPT modeDenys Vlasenko
The var_LINENO3.tests fails for hush: it does start from 0, but does not increment. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07ash: fix LINENO in functionsDenys Vlasenko
From larger patch by Roberto A. Foglietta <roberto.foglietta@gmail.com> function old new delta evalfun 348 369 +21 ash_main 1202 1218 +16 setinputstring 65 73 +8 lookupvar 116 106 -10 evaltree 772 753 -19 evalsubshell 192 173 -19 evalfor 175 156 -19 evalcase 273 254 -19 evalcommand 1560 1536 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/6 up/down: 45/-110) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-07hush: fix set -n to act immediately, not just after run_list()Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-27shell: update psubst testcasesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-26hush: implement $'str' bashismDenys Vlasenko
function old new delta parse_dollar_squote - 441 +441 encode_then_expand_vararg 359 380 +21 parse_stream 2252 2271 +19 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 481/0) Total: 481 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-07-25ahell: update testsuiteDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-19hush: fix bkslash+newline handling and number validation in ${NN} and ${#NN}Denys Vlasenko
Entering "${1a}" into interactive shell was making it exit. function old new delta parse_dollar 824 958 +134 i_getch_and_eat_bkslash_nl - 44 +44 parse_expr 917 938 +21 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 199/0) Total: 199 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15hush: fix handling of \^C and "^C"Denys Vlasenko
function old new delta parse_stream 2238 2252 +14 encode_string 243 256 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0) Total: 27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25typo fixDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25hush: fix this case: echo "SCRIPT" | hushDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-23hush: fix fallout from tweaking ${var:START:LEN} codeDenys Vlasenko
function old new delta expand_one_var 2344 2353 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-11-01hush: document bugs in [[ =~ ]] comparisonDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31hush: add tests for unquoted < > in [[ ]]Denys Vlasenko
They pass. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-31shell: better support of [[ ]] bashismDenys Vlasenko
Still rather rudimentary for ash function old new delta binop 433 589 +156 check_operator 65 101 +36 done_word 736 769 +33 test_main 405 418 +13 parse_stream 2227 2238 +11 ops_texts 124 133 +9 ops_table 80 86 +6 run_pipe 1557 1562 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0) Total: 269 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: output bash-compat killing signal namesDenys Vlasenko
This significantly syncronises ash-signals and hush-signals tests. function old new delta process_wait_result 449 450 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24hush: do not print killing signal name in `cmd_whihc_dies_on_signal`Denys Vlasenko
function old new delta process_wait_result 438 449 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29shell: add testsuite for "wait $pid" waiting for other tasksDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-07-31shell: Fix "read -d ''" behaviorChristian Eggers
With bash's read builtin it is possible to read from a file (e.g. device-tree) until the first '\0' character: IFS= read -r -d '' VARIABLE < file In busybox ash the -d extension is also implemented, but checking the read character for '\0' has to be performed after comparing with the delimiter. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-26shells: fix exitcode_trapN tests to avoid racesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21ash: expand: Ensure result is escaped in cvtnumDenys Vlasenko
Upstream commit: Date: Fri, 1 Jun 2018 18:25:29 +0800 expand: Ensure result is escaped in cvtnum The minus sign generated from arithmetic expansion is currently unquoted which causes anomalies when the result is used in where the quoting matters. This patch fixes it by explicitly calling memtodest on the result in cvtnum. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21hush: make "exit" in trap use pre-trap exitcode - fix for nested trapDenys Vlasenko
function old new delta check_and_run_traps 276 278 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20hush: implement "return NUM in trap sets $? after trap"Denys Vlasenko
function old new delta builtin_return 47 67 +20 check_and_run_traps 243 259 +16 run_pipe 1583 1597 +14 hush_main 1076 1086 +10 run_list 1054 1055 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-19ash,hush: testcase for "exit" without arguments in a trapDenys Vlasenko
hush fails this one Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17ash: expand: Fix trailing newlines processing in backquote expandingDenys Vlasenko
Upstream commit: Date: Mon, 29 Apr 2019 19:13:37 +0500 expand: Fix trailing newlines processing in backquote expanding According to POSIX.1-2008 we should remove newlines only at the end of the substitution. Newlines-only substitions causes dash to remove newlines before beggining of the substitution. The following code: cat <<END 1 $(echo "") 2 END prints "1<newline>2" instead of expected "1<newline><newline>2". This patch fixes trailing newlines processing in backquote expanding. Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-17ash: parser: Only accept single-digit parameter expansion outside of bracesDenys Vlasenko
Upstream commit: Date: Mon, 27 May 2019 13:39:37 +0800 parser: Only accept single-digit parameter expansion outside of braces This patch should fix the problem. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-11-01hush: restore redirected stdinDenys Vlasenko
function old new delta restore_redirects 52 95 +43 save_fd_on_redirect 243 253 +10 hfopen 90 99 +9 fgetc_interactive 259 261 +2 builtin_type 117 115 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 64/-2) Total: 62 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-19hush: remove test for "echo ${-}" errorring out - now it worksDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-15hush: fix quoted "${notexist-}" expansion to not disappearDenys Vlasenko
function old new delta expand_one_var 2296 2311 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14shells: add tests for backslashes in export VAR=VALDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-07ash: expand: Do not quote backslashes in unquoted parameter expansionDenys Vlasenko
Upstream commit: Date: Wed, 28 Mar 2018 18:37:51 +0800 expand: Do not quote backslashes in unquoted parameter expansion Here is a better example: a="/*/\nullx" b="/*/\null"; printf "%s\n" $a $b dash currently prints /*/\nullx /*/\null bash prints /*/\nullx /dev/null You may argue the bash behaviour is inconsistent but it actually makes sense. What happens is that quote removal only applies to the original token as seen by the shell. It is never applied to the result of parameter expansion. Now you may ask why on earth does the second line say "/dev/null" instead of "/dev/\null". Well that's because it is not the quote removal step that removed the backslash, but the pathname expansion. The fact that the /de\v does not become /dev even though it exists is just the result of the optimisation to avoid unnecessarily calling stat(2). I have checked POSIX and I don't see anything that forbids this behaviour. So going back to dash yes I think we should adopt the bash behaviour for pathname expansion and keep the existing case semantics. This patch does exactly that. Note that this patch does not work unless you have already applied https://patchwork.kernel.org/patch/10306507/ because otherwise the optimisation mentioned above does not get detected correctly and we will end up doing quote removal twice. This patch also updates expmeta to handle naked backslashes at the end of the pattern which is now possible. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta expmeta 618 653 +35 memtodest 146 147 +1 Tested to work with both ASH_INTERNAL_GLOB on and off. hush does not handle this correctly. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05hush: adopt ash's quote_in_varexp1.testsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: expand: Fix ghost fields with unquoted $@/$*Denys Vlasenko
Upstream commit: Date: Fri, 23 Mar 2018 18:58:47 +0800 expand: Fix ghost fields with unquoted $@/$* You're right. The proper fix to this is to ensure that nulonly is not set in varvalue for $*. It should only be set for $@ when it's inside double quotes. In fact there is another bug while we're playing with $@/$*. When IFS is set to a non-whitespace character such as :, $* outside quotes won't remove empty fields as it should. This patch fixes both problems. Reported-by: Martijn Dekker <martijn@inlv.org> Suggested-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta argstr 1111 1113 +2 evalvar 571 569 -2 varvalue 579 576 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 2/-5) Total: -3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: eval: Variable assignments on functions are no longer persistentDenys Vlasenko
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-04ash,hush: properly handle ${v//pattern/repl} if pattern starts with /Denys Vlasenko
Closes 2695 function old new delta parse_dollar 762 790 +28 subevalvar 1258 1267 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28hush: fix another case where empty "for" wasn't setting exitcode to 0Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>