aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* hush: less mind-bending set_vars_and_save_old()Denys Vlasenko2018-04-051-71/+101
| | | | | | | | | | | | | | function old new delta run_pipe 1651 1701 +50 set_local_var 510 557 +47 pseudo_exec_argv 544 581 +37 redirect_and_varexp_helper 64 56 -8 set_vars_and_save_old 164 149 -15 unset_local_var 274 256 -18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/3 up/down: 134/-41) Total: 93 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: "no logic changes" in last commit was not true, fix it upDenys Vlasenko2018-04-051-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make run_pipe code simpler to understand, no logic changesDenys Vlasenko2018-04-051-66/+57
| | | | | | | function old new delta run_pipe 1641 1651 +10 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-055-82/+93
| | | | | | | | | | | | | | | | | 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: make var nesting code independent of "local" supportDenys Vlasenko2018-04-041-40/+61
| | | | | | | | | | | | | | | | | | | | | | Also, add code to abort at ~65000 function recursion depth. SEGVing is not as nice as exiting with a message (and restoring termios!): $ f() { echo -n .; f; }; f ....<many dots later>....hush: fatal recursion (depth 65281) function old new delta run_pipe 1826 1890 +64 pseudo_exec_argv 544 554 +10 parse_and_run_file 71 80 +9 i_getch 104 107 +3 done_command 99 102 +3 set_local_var 508 510 +2 helper_export_local 214 215 +1 builtin_local 49 46 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/1 up/down: 92/-3) Total: 89 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix for readonly vars in "ro=A ro=B cmd" caseDenys Vlasenko2018-04-043-13/+21
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: unbreak PS1 parsing after "ash: parser: Add syntax stack..." commitDenys Vlasenko2018-04-041-1/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: support "f() (cmd)" functionsDenys Vlasenko2018-04-036-40/+59
| | | | | | | | | Many other shells support this construct function old new delta parse_stream 2950 3018 +68 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix mishandling of "true | f() { echo QWE; }"Denys Vlasenko2018-04-031-0/+9
| | | | | | | function old new delta run_pipe 1820 1826 +6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "set -e; false || x=1; echo OK"Denys Vlasenko2018-04-035-7/+43
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: one-word, no-globbing handling of local/export/readonly argsDenys Vlasenko2018-04-031-21/+32
| | | | | | | function old new delta done_word 738 790 +52 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Fix parameter expansion inside inner double quotesDenys Vlasenko2018-04-023-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Upstream email: parser: Fix parameter expansion inside inner double quotes The parsing of parameter expansion inside inner double quotes breaks because we never look for ENDVAR while innerdq is true. echo "${x#"${x+''}"''} This patch fixes it by pushing the syntax stack if innerdq is true and we enter a new parameter expansion. This patch also fixes a corner case where a bad substitution error occurs within arithmetic expansion. Reported-by: Denys Vlasenko <vda.linux@googlemail.com> Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta readtoken1 2880 2898 +18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a backslash-removal bug in caseDenys Vlasenko2018-04-025-3/+37
| | | | | | | function old new delta run_list 1270 1053 -217 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: expand: Fix bugs with words connected to the right of $@Denys Vlasenko2018-04-025-4/+13
| | | | | | | | | | | | | | | Upstream email: This is actually composed of two bugs. First of all our tracking of quotemark is wrong so anything after "$@" becomes quoted. Once we fix that then the problem is that the first space character after "$@" is not recognised as an IFS. This patch fixes both. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: redir: Fix typo in noclobber codeDenys Vlasenko2018-04-021-1/+1
| | | | | | Upstream commit "redir: Fix typo in noclobber code" Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Fix single-quoted patterns in here-documentsDenys Vlasenko2018-04-023-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: From: Herbert Xu <herbert@gondor.apana.org.au> Date: Fri, 9 Mar 2018 23:07:53 +0800 parser: Fix single-quoted patterns in here-documents The script x=* cat <<- EOF ${x#'*'} EOF prints * instead of nothing as it should. The problem is that when we're in sqsyntax context in a here-document, we won't add CTLESC as we should. This patch fixes it: Reported-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: remove stray debugging printoutDenys Vlasenko2018-04-021-1/+0
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: parser: Add syntax stack for recursive parsingDenys Vlasenko2018-04-0219-121/+168
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* hush: update information comment about heredoc discrepancyDenys Vlasenko2018-04-011-7/+12
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: new function bb_die_memory_exhaustedDenys Vlasenko2018-04-011-2/+2
| | | | | | | | | | | | | | | | | | | | function old new delta bb_die_memory_exhausted - 10 +10 xstrdup 28 23 -5 xsetenv 27 22 -5 xrealloc 32 27 -5 xputenv 22 17 -5 xmalloc 30 25 -5 xfdopen_helper 40 35 -5 xasprintf 44 39 -5 wget_main 2387 2382 -5 open_socket 54 49 -5 glob_brace 419 414 -5 bb_get_chunk_from_file 146 141 -5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/11 up/down: 10/-55) Total: -45 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add a comment where we differ from bash wrt heredoc EOF mark handlingDenys Vlasenko2018-04-013-15/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* parser: Fix backquote support in here-document EOF markDenys Vlasenko2018-04-015-0/+36
| | | | | | | | | | | | | | | | | | | | Upstream commit: Author: Herbert Xu <herbert@gondor.apana.org.au> Date: Thu Mar 15 18:27:30 2018 +0800 parser: Fix backquote support in here-document EOF mark Currently using backquotes in a here-document EOF mark is broken because dash tries to do command substitution on it. This patch fixes it by checking whether we're looking for an EOF mark during tokenisation. Reported-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> With added fix for quoted-ness of the EOF mark. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: handle a few more bkslash-newline casesDenys Vlasenko2018-04-0110-3/+53
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shells: fix var_LINENO1.tests false positive, add it to ash tests tooDenys Vlasenko2018-03-313-1/+15
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix heredoc_bkslash_newline1.tests failureDenys Vlasenko2018-03-311-35/+42
| | | | | | | | function old new delta parse_stream 2787 2827 +40 builtin_type 117 115 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: use pgetc_eatbnl() in more placesDenys Vlasenko2018-03-317-35/+191
| | | | | | | | | | | | | | | | | | | | | Part of upstream commit: Date: Thu Mar 8 08:37:11 2018 +0100 Author: Harald van Dijk <harald@gigawatt.nl> parser: use pgetc_eatbnl() in more places dash has a pgetc_eatbnl function in parser.c which skips any backslash-newline combinations. It's not used everywhere it could be. There is also some duplicated backslash-newline handling elsewhere in parser.c. Replace most of the calls to pgetc() with calls to pgetc_eatbnl() and remove the duplicated backslash-newline handling. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Not adding "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes, since readtoken1() handles the "starts with backslash + newline" case itself. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: 'nolog' and 'debug' options cause "$-" to wreak havocMartijn Dekker2018-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Tue Mar 6 17:40:37 2018 +0000 expand: 'nolog' and 'debug' options cause "$-" to wreak havoc Op 29-03-17 om 20:02 schreef Martijn Dekker: > Bug: if either the 'nolog' or the 'debug' option is set, trying to > expand "$-" silently aborts parsing of an entire argument. > > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; set +o nolog; echo "|$- are the options|"' > | > |uCf are the options| > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; set +o debug; echo "|$- are the options|"' > | > |uCf are the options| This turned out to be easy to fix. The routine producing the "$-" expansion failed to skip options for which there is no option letter, but only a long-form name. In dash, 'nolog' and 'debug' are currently the only two such options. Patch below. - Martijn Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> In bbox ash, pipefail is the option which exhibited this. Signed-off-by: Martijn Dekker <martijn@inlv.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a signedness bugDenys Vlasenko2018-03-311-1/+1
| | | | | | | | | | | | | | | | Testcase: set -- a ""; space=" "; printf "<%s>\n" "$@"$space Before: <a > After: <a> <> It usually does not bite since bbox forces -funsigned-char build. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: new test dollar_repl_slash_bash2.testsDenys Vlasenko2018-03-304-0/+6
| | | | | | This fails for ash. hush works. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix "char == CTLfoo" comparison signedness bugDenys Vlasenko2018-03-301-3/+3
| | | | | | | It usually does not bite since bbox forces -funsigned-char build. But for some reason void linux people disabled that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: use F_DUPFD_CLOEXEC and O_CLOEXECDenys Vlasenko2018-03-301-9/+16
| | | | | | | | | | | | function old new delta setjobctl 371 367 -4 setinputfile 226 220 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Based on patch by Mark Marshall <mark.marshall@omicronenergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add a FIXME commentDenys Vlasenko2018-03-281-0/+6
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: fix "saved" redirected fds still visible in childrenDenys Vlasenko2018-03-2814-13/+92
| | | | | | | | | | Based on a patch by Mark Marshall <mark.marshall@omicronenergy.com> function old new delta dup_CLOEXEC - 49 +49 fcntl_F_DUPFD 46 - -46 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: code shrinkDenys Vlasenko2018-03-061-6/+7
| | | | | | | | | | | | function old new delta run_pipe 1589 1591 +2 pseudo_exec_argv 374 375 +1 builtin_type 114 115 +1 find_function 8 - -8 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 3/0 up/down: 4/-8) Total: -4 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a='a\\'; echo "${a%\\\\}"Denys Vlasenko2018-03-0210-3/+39
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.testsDenys Vlasenko2018-03-028-5/+50
| | | | | | | | | It turns out bkslash_in_varexp.tests was a bash bug :] ash and hush fail "corrected" bkslash_in_varexp.tests as well, just not as badly as I thought (hush gets half of the cases right). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: two new tests, both fail for ash and hushDenys Vlasenko2018-03-028-0/+44
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: simplify process_command_subs()Denys Vlasenko2018-02-131-11/+9
| | | | | | | | | | | | | | | | | Incidentally, this fixes LINENO bug here: echo "1:${LINENO}" echo "2:`echo; echo`" # was counting lines in the `cmd` output as LINENO++ echo "3:${LINENO}" function old new delta parse_and_run_file 53 71 +18 expand_vars_to_list 1187 1164 -23 setup_file_in_str 25 - -25 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 18/-48) Total: -30 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash : fix double-quoted "\z" handlingDenys Vlasenko2018-02-135-6/+113
| | | | | | | function old new delta readtoken1 2602 2608 +6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: probably fixing a bug in last LINENO fixDenys Vlasenko2018-02-081-11/+6
| | | | | | | | | | I don't have an example of mishandled script, but the logic looked wrong: it could sometimes treat newlines as if they are spaces. function old new delta parse_stream 2788 2787 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: LINENO fixDenys Vlasenko2018-02-081-24/+77
| | | | | | | | | | | | | | | | | | | Script triggering the bug: t=0 echo "at line ${LINENO}" while [ ${t} -lt 10 ]; do echo "at line ${LINENO}" # LINENO was 3 instead of 4 here t=$((t+1)) done function old new delta parse_stream 2754 2788 +34 done_word 711 738 +27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: protect against self-modifying trap codeDenys Vlasenko2018-01-301-1/+3
| | | | | | | function old new delta check_and_run_traps 211 236 +25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: make it possible to disable "const global ptr" optimizationDenys Vlasenko2018-01-281-3/+16
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: handle $((NUM++...) like bash does. Closes 10706Denys Vlasenko2018-01-289-14/+57
| | | | | | | function old new delta evaluate_string 680 729 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: add LINENO supportDenys Vlasenko2018-01-274-534/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is a backport from dash of the combination of: [SHELL] Add preliminary LINENO support [VAR] Fix varinit ordering that broke fc [SHELL] Improve LINENO support function old new delta parse_command 1604 1677 +73 calcsize 156 223 +67 copynode 196 258 +62 evalcommand 1546 1606 +60 ash_main 1046 1103 +57 lookupvar 51 106 +55 evalcase 269 317 +48 evaltree 501 547 +46 evalfor 156 200 +44 evalsubshell 156 195 +39 raise_error_syntax 11 29 +18 varinit_data 120 132 +12 evalfun 270 280 +10 funcline - 4 +4 cmdtxt 569 572 +3 trapcmd 306 304 -2 ash_vmsg 153 150 -3 startlinno 4 - -4 funcnest 4 - -4 xxreadtoken 263 250 -13 readtoken1 2645 2602 -43 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 14/4 up/down: 598/-69) Total: 529 bytes text data bss dec hex filename 932834 481 6864 940179 e5893 busybox_old 933375 481 6856 940712 e5aa8 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add HUSH_BASH_SOURCE_CURDIR config option, to be on par with ashDenys Vlasenko2018-01-272-3/+10
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix dot builtin to not search current directoryDenys Vlasenko2018-01-271-0/+5
| | | | | | | function old new delta builtin_source 182 209 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: introduce a config option to search current directory for sourced filesDenys Vlasenko2018-01-261-1/+12
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash testsuite: add two hush tests from last commitDenys Vlasenko2018-01-254-0/+10
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix two corner cases in ${v/pattern/repl}. Closes 10686Denys Vlasenko2018-01-255-2/+21
| | | | | | | function old new delta expand_one_var 1592 1618 +26 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>