aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_test/hush-vars (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ash: disable check for "good" function name, bash does not check thisDenys Vlasenko2023-07-041-2/+2
| | | | | | | | | | function old new delta .rodata 105304 105261 -43 parse_command 1696 1633 -63 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106) Total: -106 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: don't read past end of var in subvareval for bash substitutionsSören Tempel2022-03-012-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* ash: LINENO starts from 0 in -c SCRIPT modeDenys Vlasenko2021-09-072-0/+4
| | | | | | 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>
* ash: fix LINENO in functionsDenys Vlasenko2021-09-072-0/+11
| | | | | | | | | | | | | | | | | | | 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>
* hush: implement $'str' bashismDenys Vlasenko2021-07-262-0/+2
| | | | | | | | | | | 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>
* ahell: update testsuiteDenys Vlasenko2021-07-251-3/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix bkslash+newline handling and number validation in ${NN} and ${#NN}Denys Vlasenko2021-06-191-1/+1
| | | | | | | | | | | | | 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>
* hush: fix fallout from tweaking ${var:START:LEN} codeDenys Vlasenko2020-12-232-0/+3
| | | | | | | function old new delta expand_one_var 2344 2353 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Only accept single-digit parameter expansion outside of bracesDenys Vlasenko2020-02-172-0/+7
| | | | | | | | | | | | | 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>
* hush: remove test for "echo ${-}" errorring out - now it worksDenys Vlasenko2019-05-192-3/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix quoted "${notexist-}" expansion to not disappearDenys Vlasenko2019-05-152-0/+7
| | | | | | | function old new delta expand_one_var 2296 2311 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: expand: Fix ghost fields with unquoted $@/$*Denys Vlasenko2018-08-052-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* ash,hush: properly handle ${v//pattern/repl} if pattern starts with /Denys Vlasenko2018-08-042-0/+5
| | | | | | | | | | | | 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>
* hush: IFS fixesDenys Vlasenko2018-04-112-0/+9
| | | | | | | | | | | | | | | | | | $ IFS=": "; x=" "; set x $x; for v; do echo "|$v|"; done |x| $ IFS=": "; x=":"; set x $x; for v; do echo "|$v|"; done |x| || function old new delta run_pipe 1789 1870 +81 expand_on_ifs 310 361 +51 pseudo_exec_argv 588 591 +3 builtin_local 50 53 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 138/0) Total: 138 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Allow newlines within parameter substitutionDenys Vlasenko2018-04-112-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Thu, 22 Mar 2018 21:41:24 +0800 parser: Allow newlines within parameter substitution On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote: > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote: > > > > Okay, it can be trivially modified to something that does work in other > > shells (even if it were actually executed), but gets rejected at parse time > > by dash: > > > > if false; then > > : ${$+ > > } > > fi > > That's just a bug in dash's parser with ${} in general, because > it bombs out without the if clause too: > > : ${$+ > } This patch fixes the parsing of newlines with parameter substitution. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a bug where we don't properly handle f() { a=A; b=B; }; a= fDenys Vlasenko2018-04-054-0/+22
| | | | | | | | | | | | | | | | | function old new delta unset_local_var 20 274 +254 leave_var_nest_level - 98 +98 set_vars_and_save_old 128 164 +36 enter_var_nest_level - 32 +32 builtin_local 46 50 +4 pseudo_exec_argv 554 544 -10 redirect_and_varexp_helper 77 64 -13 run_pipe 1890 1641 -249 unset_local_var_len 267 - -267 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 3/3 up/down: 424/-539) Total: -115 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix for readonly vars in "ro=A ro=B cmd" caseDenys Vlasenko2018-04-042-0/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Add syntax stack for recursive parsingDenys Vlasenko2018-04-024-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This closes 10821. Upstream patch: From: Herbert Xu <herbert@gondor.apana.org.au> Date: Fri, 9 Mar 2018 00:14:02 +0800 parser: Add syntax stack for recursive parsing Without a stack of syntaxes we cannot correctly these two cases together: "${a#'$$'}" "${a#"${b-'$$'}"}" A recursive parser also helps in some other corner cases such as nested arithmetic expansion with paratheses. This patch adds a syntax stack allocated from the stack using alloca. As a side-effect this allows us to remove the naked backslashes for patterns within double-quotes, which means that EXP_QPAT also has to go. This patch also fixes removes any backslashes that precede right braces when they are present within a parameter expansion context, and backslashes that precede double quotes within inner double quotes inside a parameter expansion in a here-document context. The idea of a recursive parser is based on a patch by Harald van Dijk. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> var_bash3, var_bash4 and var_bash6 tests are updated with the output given by bash-4.3.43 With this patch, the following tests now pass for ash: dollar_repl_slash_bash2.tests squote_in_varexp2.tests squote_in_varexp.tests var_bash4.tests function old new delta readtoken1 2615 2874 +259 synstack_push - 54 +54 evalvar 574 571 -3 rmescapes 330 310 -20 subevalvar 1279 1258 -21 argstr 1146 1107 -39 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/4 up/down: 313/-83) Total: 230 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shells: fix var_LINENO1.tests false positive, add it to ash tests tooDenys Vlasenko2018-03-311-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix two corner cases in ${v/pattern/repl}. Closes 10686Denys Vlasenko2018-01-254-0/+10
| | | | | | | function old new delta expand_one_var 1592 1618 +26 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: implement $LINENO bashismDenys Vlasenko2018-01-192-0/+14
| | | | | | | | | | | | | | | | function old new delta run_pipe 1697 1774 +77 unset_local_var_len 258 301 +43 hush_main 1009 1051 +42 set_local_var 516 554 +38 parse_and_run_file 42 75 +33 i_getch 96 116 +20 .rodata 18858 18876 +18 done_command 106 122 +16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 287/0) Total: 287 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: echo ${?:0} was fixed sometime ago, enable it in testsDenys Vlasenko2018-01-132-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix false positive in unset.testsDenys Vlasenko2017-08-291-0/+6
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: remove ${#+} tests, it is not a valid constructDenys Vlasenko2017-07-262-3/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix ${##}, ${#?}, ${#!} handlingDenys Vlasenko2017-07-263-1/+43
| | | | | | | | | | function old new delta parse_dollar 786 820 +34 expand_one_var 1579 1592 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 47/0) Total: 47 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: [VAR] Move unsetvar functionality into setvareqDenys Vlasenko2017-07-252-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Tue, 25 May 2010 20:55:05 +0800 [VAR] Move unsetvar functionality into setvareq This patch moves the unsetvar code into setvareq so that we can no have a pathological case of an unset variable hanging around unless it has a bit pinning it like VEXPORT. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta setvareq 227 303 +76 expmeta 517 521 +4 localcmd 364 366 +2 unsetcmd 96 76 -20 unsetvar 129 7 -122 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/2 up/down: 82/-142) Total: -60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: import param_expand_default.tests from hushDenys Vlasenko2017-07-251-2/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: treat ${#?} as "length of $?"Denys Vlasenko2017-07-252-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: add a few tests from hush-vars/*Denys Vlasenko2017-07-254-23/+32
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix readonly2.tests failureDenys Vlasenko2017-07-182-0/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: another testcase for "READONLY_VAR=VAL BLTIN ..."Denys Vlasenko2017-07-184-5/+27
| | | | | | Currently fails. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do not assign to readonly VAR in "VAR=VAL CMD" syntax tooDenys Vlasenko2017-07-182-11/+25
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add readonly testcase, fix falloutDenys Vlasenko2017-07-182-0/+36
| | | | | | | | | | function old new delta helper_export_local 185 214 +29 run_pipe 1549 1560 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0) Total: 40 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: support ${VAR:N:-M}Denys Vlasenko2017-07-172-0/+47
| | | | | | | | function old new delta expand_one_var 1602 1615 +13 builtin_type 114 116 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* typo fixDenys Vlasenko2017-07-061-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: implement negative start in the ${v: -n[:m]} idiomDenys Vlasenko2017-07-062-0/+17
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: "adopt" ash var-utf8-length.testsDenys Vlasenko2017-07-062-0/+5
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: [PARSER] Fix parsing of ${##1}Denys Vlasenko2016-10-262-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Thu, 4 Oct 2007 22:15:10 +0800 [PARSER] Fix parsing of ${##1} Previously dash treated ${##1} as a length operation. This patch fixes that. Test case: set -- a echo ${##1}OK Old result: 1OK New result: OK This was a real bug in ash (but not in hush). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add var4.tests, var5.testsDenys Vlasenko2016-10-024-0/+22
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix var3.testsDenys Vlasenko2016-10-023-0/+6
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* sh testsuite: sync ash-vars/ and hush-vars/Denys Vlasenko2016-10-023-0/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: expand: Fixed "$@" expansion when EXP_FULL is falseDenys Vlasenko2016-10-022-0/+37
| | | | | | | | | | | | | | | | | | | Upstream commit: Date: Thu, 1 Jan 2015 07:53:10 +1100 expand: Fixed "$@" expansion when EXP_FULL is false The commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ([EXPAND] Split unquoted $@/$* correctly when IFS is set but empty) broke the case where $@ is in quotes and EXP_FULL is false. In that case we should still emit IFS as field splitting is not performed. Reported-by: Juergen Daubert <jue@jue.li> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: [EXPAND] Do not split quoted VSLENGTH and VSTRIMDenys Vlasenko2016-10-014-0/+33
| | | | | | | | | | | | | | Upstream patch: Date: Wed, 8 Oct 2014 15:42:08 +0800 [EXPAND] Do not split quoted VSLENGTH and VSTRIM Currently VSLENGTH and VSTRIM* are field-split even within quotes. This is obviously wrong. This patch fixes that. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but emptyDenys Vlasenko2016-10-012-0/+46
| | | | | | | | | | | | | | Upstream commit: Date: Wed, 8 Oct 2014 15:24:23 +0800 [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty Currently we do not field-split $@/$* when it isn't quoted and IFS is set but empty. This is obviously wrong. This patch fixes this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell testsuite: add trailing newline to var_unbackslash1.testsDenys Vlasenko2016-09-291-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix arithmetic closing )) split by backslash-newlineDenys Vlasenko2016-09-292-0/+24
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: rework input char buffering to allow more than one-deep peekDenys Vlasenko2016-09-292-0/+18
| | | | | | | | | | | | | | | | | | | | | This fixes backslash+newline continuation in $VAR\ NAME construct. (ash has a bug there as well). function old new delta file_peek2 - 74 +74 parse_dollar 746 773 +27 expand_vars_to_list 1143 1167 +24 setup_string_in_str 32 46 +14 setup_file_in_str 33 47 +14 file_get 264 278 +14 static_peek2 - 7 +7 file_peek 91 72 -19 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19) Total: 155 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add recent ash tests to hush testsuite too (they all pass for hush)Denys Vlasenko2015-05-1818-0/+29
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: partially fix wrong expansion on $IFS (bug 4027).Denys Vlasenko2011-08-012-0/+20
| | | | | | | | | | | | | | | | In the added testcase, before patch we failed 8 out of 9 tests, now we fail only 2 (4th and 5th). function old new delta expand_on_ifs 225 258 +33 expand_vars_to_list 1038 1054 +16 o_save_ptr_helper 115 119 +4 builtin_umask 132 133 +1 o_addQstr 165 161 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 54/-4) Total: 50 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do fewer strdups in % and hash expansionsDenys Vlasenko2010-09-102-0/+14
| | | | | | | | function old new delta builtin_umask 133 132 -1 expand_one_var 1552 1543 -9 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>