aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
AgeCommit message (Collapse)Author
2020-02-16ash: builtin: Mark more regular built-insDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:49 +0800 builtin: Mark more regular built-ins This patch marks the following built-ins as regular, meaning that they cannot be overriden using PATH search: hash pwd type ulimit Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: jobs: Replace some uses of fmtstr with stpcpy/stpncpyDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:45 +0800 jobs: Replace some uses of fmtstr with stpcpy/stpncpy Some uses of fmtstr, particularly the ones without a format string, can be replaced with stpcpy or stpncpy. This patch does that so we don't have to introduce unnecessary format strings in order to silence compiler warnings. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: output: Fix fmtstr return valueDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:44 +0800 output: Fix fmtstr return value The function fmtstr is meant to return the actual length of output produced, rather than the untruncated length. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: main: Only set savestatus in exitcmdDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:38 +0800 main: Only set savestatus in exitcmd Currently exitcmd sets exitstatus and then savestatus if the latter was previously set. In fact, as exitcmd always raises an exception and will either end up in the setjmp call in main() or exitshell(), where exitstatus is always replaced by savestatus if set, we only need to set savestatus. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: [BUILTIN] Exit without arguments in a trap should use status outside trapsDenys Vlasenko
Upstream commit: Date: Mon Oct 6 10:39:47 2014 +0800 [BUILTIN] Exit without arguments in a trap should use status outside traps POSIX now requires that exit without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: parser: Fix incorrect eating of backslash newlinesDenys Vlasenko
Keeping up with upstream (in our case, 'before patch' code is not buggy). Upstream commit: Date: Fri, 11 May 2018 23:41:25 +0800 parser: Fix incorrect eating of backslash newlines With the introduction of synstack->syntax, a number of references to the syntax variable was missed during the conversion. This causes backslash newlines to be incorrectly removed in single quote context. This patch also combines these calls into a new helper function pgetc_top. Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...") Reported-by: Leah Neukirchen <leah@vuxu.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-16ash: use pgetc_eatbnl() in more places, take 2Denys Vlasenko
Adding previously skipped "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes from 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> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston
function old new delta complete_cmd_dir_file 678 830 +152 get_builtin_name - 35 +35 optschanged 125 132 +7 hush_main 1069 1076 +7 save_command_ps_at_cur_history 76 78 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0) Total: 203 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-01-29ash: improve expandstr()Ron Yorston
The dash maintainer recently posted a fix for issues with expanding PS1. These had already been fixed differently in BusyBox ash. Borrow a couple of improvements: - Use a single call to setjmp() to trap errors in both readtoken1() and expandarg(). - In case of error set the prompt to the literal value of PS1 rather than the half-digested nonsense in stackblock() which might include ugly control characters. function old new delta expandstr 353 300 -53 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-10-25clang/llvm 9 fix - do not eliminate a store to a fake "const"Denys Vlasenko
This is *much* better (9 kbytes better) than dropping "*const" optimization trick. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-09-05ash: add a FIXME commentDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-08-02ash: fix set -o to not show "nameless" optionsDenys Vlasenko
Patch by Martijn Dekker <martijn@inlv.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-31ash: only catch unexpected exceptions in PS1 expansionRon Yorston
Commit d1a2fa2a4 (ash: catch error in arithmetic expansion in PS1) catches all exceptions raised by expandarg(). Some exceptions, such as the EXEXIT raised when command expansion is used, are expected: export PS1='$(echo "$ ")' These should be processed normally or the shell hangs at the prompt. function old new delta expandstr 344 353 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-03ash,hush: show 'c' in $- if run in "sh -c CMD"Denys Vlasenko
function old new delta options 552 599 +47 expand_one_var 2375 2385 +10 optletters_optnames 60 64 +4 hush_main 1108 1111 +3 ash_main 1150 1152 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 66/0) Total: 66 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-06-01ash: allocate line editing structure only if neededDenys Vlasenko
function old new delta optschanged 91 128 +37 historycmd 13 17 +4 setcmd 80 78 -2 ash_main 1167 1150 -17 options 576 552 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/3 up/down: 41/-43) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-19ash: catch error in arithmetic expansion in PS1Ron Yorston
Setting PS1 to: PS1='$((123+))' causes the shell to enter an infinite error loop: sh: arithmetic syntax error Catch any exception raised by expandarg() in expandstr() and allow processing to continue. function old new delta expandstr 262 344 +82 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 82/0) Total: 82 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-19ash: prevent error in backquotes in PS1 from exiting shellRon Yorston
Setting PS1 to: PS1='`xxx(`' causes the shell to terminate with the error: sh: syntax error: unexpected end of file (expecting ")") This happens because old-style backquotes require the input to be reread and thus call setinputstring() a second time. Prevent the problem by unwinding all recently opened files in expandstr(). function old new delta unwindfiles - 22 +22 expandstr 247 262 +15 forkchild 631 625 -6 evalcommand 1694 1685 -9 ash_main 1346 1336 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/3 up/down: 37/-25) Total: 12 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-16ash: add bash-compatible EPOCH variablesRon Yorston
Bash 5.0 added the dynamic variable EPOCHSECONDS and EPOCHREALTIME which return the number of seconds since the Unix Epoch as an integer or float. These are useful for logging or tracing. function old new delta change_epoch - 78 +78 .rodata 175167 175235 +68 varinit_data 264 312 +48 change_seconds - 24 +24 change_realtime - 24 +24 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 2/0 up/down: 242/0) Total: 242 bytes text data bss dec hex filename 938508 4203 1888 944599 e69d7 busybox_old 938702 4203 1888 944793 e6a99 busybox_unstripped v2: Cast tv_sec and tv_usec to unsigned quantities. Add brackets to macros. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-16ash: an unset dynamic variable should not be dynamicRon Yorston
Commit b28d4c346 (ash: [VAR] Move unsetvar functionality into setvareq) dropped the code that caused dynamic variables to lose their special properties when unset. Add it back again. function old new delta setvareq 346 360 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 14/0) Total: 14 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-04-02ash: distinguish 'wait -n' from other bashismsRon Yorston
Add a specific define to indicate which bash compatibility code implements 'wait -n'. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-03-27ash: add "wait -n" bashismDenys Vlasenko
function old new delta waitcmd 205 288 +83 dowait 405 444 +39 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 122/0) Total: 122 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-25ash: eval: avoid leaking memory associated with redirections. Closes 7748Ron Yorston
The following constructs result in ever-increasing memory usage: while true; do { true; } </dev/null; done while true; do ( true; ) </dev/null; done For comparison, bash displays static memory usage in both cases. This has been fixed in dash by commit 2bc6caa. The maintainer writes: I have simplified evaltree so that it simply sets the stack mark unconditionally. This allows us to remove the stack marks in the functions called by evaltree. Closes BusyBox bug 7748. function old new delta evaltree 606 632 +26 evalcommand 1724 1696 -28 evalcase 382 351 -31 evalfor 230 196 -34 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 26/-93) Total: -67 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28config: update size informationDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08inetd: suppress aliasing warningDenys Vlasenko
function old new delta sigprocmask2 - 8 +8 wait_for_child_or_signal 213 218 +5 dowait 424 429 +5 block_CHLD_HUP_ALRM 62 59 -3 sigprocmask_SIG_SETMASK 16 - -16 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/1 up/down: 18/-19) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-08suppress gcc 8 aliasing warningsDenys Vlasenko
function old new delta sigprocmask_SIG_SETMASK - 16 +16 wait_for_child_or_signal 221 213 -8 dowait 432 424 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27hush: allow hush to run embedded scriptsRon Yorston
Embedded scripts require a shell to be present in the BusyBox binary. Allow either ash or hush to be used for this purpose. If both are enabled ash takes precedence. The size of the binary is unchanged in the default configuration: both ash and hush are present but support for embedded scripts isn't compiled into hush. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-20ash: reset tokpushback before prompting while parsing heredocChristoph Schulz
The parser reads from an already freed memory location, thereby causing unpredictable results, in the following situation: - ENABLE_ASH_EXPAND_PRMT is enabled - heredoc is being parsed - command substitution is used within heredoc Examples where this bug crops up are (PS2 is set to "> "): $ cat <<EOF > `echo abc` > EOF -sh: O: not found $ cat <<EOF > $(echo abc) > EOF -sh: {garbage}: not found The presumable reason is that setprompt_if() causes a nested expansion when ENABLE_ASH_EXPAND_PRMT is enabled, therefore leaving "wordtext" in an unusable state. However, when parseheredoc() is called, "tokpushback" is non-zero, which causes the next call to xxreadtoken() to return TWORD, causing the caller to use the invalid "wordtoken" instead of reading the next valid token. The call chain is: list() -> peektoken() [sets tokpushback to 1] -> parseheredoc() -> setprompt_if() -> pushstackmark() -> expandstr() -> readtoken1() [sets lasttoken to TWORD, wordtoken points to expanded prompt] -> popstackmark() [invalidates wordtoken, leaves lasttoken as is] -> readtoken1() -> ...parsebackq -> list() -> andor() -> pipeline() -> readtoken() -> xxreadtoken() [tokpushback non-zero, reuse lasttoken and wordtext] Note that in almost all other contexts, each call to setprompt_if() is preceded by setting "tokpushback" to zero. One exception is "oldstyle" backquote parsing in readtoken1(), but there "tokpushback" is reset afterwards. The other exception is nlprompt(), but this function is only used within readtoken1() (but in contexts where no nested calls to xxreadtoken() occur) and xxreadtoken() (where "tokpushback" is guaranteed to be zero). function old new delta parseheredoc 124 131 +7 Signed-off-by: Christoph Schulz <develop@kristov.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-17Treat custom and applet scripts as appletsRon Yorston
BusyBox has support for embedded shell scripts. Two types can be distinguished: custom scripts and scripts implementing applets. Custom scripts should be placed in the 'embed' directory at build time. They are given a default applet configuration and appear as applets to the user but no further configuration is possible. Applet scripts are integrated with the BusyBox build system and are intended to be used to ship standard applets that just happen to be implemented as scripts. They can be configured at build time and appear just like native applets. Such scripts should be placed in the 'applets_sh' directory. A stub C program should be written to provide the usual applet configuration details and placed in a suitable subsystem directory. It may be helpful to have a configuration option to enable any dependencies the script requires: see the 'nologin' applet for an example. function old new delta scripted_main - 41 +41 applet_names 2773 2781 +8 applet_main 1600 1604 +4 i2cdetect_main 672 674 +2 applet_suid 100 101 +1 applet_install_loc 200 201 +1 applet_flags 100 101 +1 packed_usage 33180 33179 -1 tryexec 159 152 -7 evalcommand 1661 1653 -8 script_names 9 - -9 packed_scripts 123 114 -9 complete_cmd_dir_file 826 811 -15 shellexec 271 254 -17 find_command 1007 990 -17 busybox_main 642 624 -18 run_applet_and_exit 100 78 -22 find_script_by_name 51 - -51 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 6/9 up/down: 58/-174) Total: -116 bytes text data bss dec hex filename 950034 477 7296 957807 e9d6f busybox_old 949918 477 7296 957691 e9cfb busybox_unstripped Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-16ash: ensure variables are fully initialised when unsetRon Yorston
When a variable is unset by calling setvar(name, NULL, 0) the code to initialise the new, empty variable fails to initialise the last character of the string. Attempts to read the contents of the unset variable will result in the uninitialised character at the end of the string being accessed. For example, running BusyBox under Valgrind and unsetting PATH: $ valgrind ./busybox_unstripped sh ==21249== Memcheck, a memory error detector ==21249== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==21249== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==21249== Command: ./busybox_unstripped sh ==21249== /data2/git/build_fix_8721 $ unset PATH /data2/git/build_fix_8721 $ 0 ==21249== Conditional jump or move depends on uninitialised value(s) ==21249== at 0x451371: path_advance (ash.c:2555) ==21249== by 0x456E22: find_command (ash.c:13407) ==21249== by 0x458425: evalcommand (ash.c:10139) ==21249== by 0x454CBC: evaltree (ash.c:9131) ==21249== by 0x456C80: cmdloop (ash.c:13164) Closes https://bugs.busybox.net/show_bug.cgi?id=8721 v2: On the dash mailing list Harald van Dijk was kind enough to point out a flaw in my reasoning and provide an alternative patch. Sadly his patch adds 2 bytes of bloat. Using xzalloc to zero the whole string gives a bloat of -3 bytes. function old new delta setvar 172 169 -3 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-06ash: minor fixesRon Yorston
Ensure that login_sh is initialised in procargs even when running an embedded script. The argc argument to ash_main isn't unused when embedded scripts are present. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: fix thinko in last commitDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: in tryexec(), ensure we don't try to run embedded scripts as appletsRon Yorston
Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: recognize embedded scripts in SH_STANDALONE modeRon Yorston
function old new delta find_script_by_name - 51 +51 shellexec 254 271 +17 find_command 990 1007 +17 evalcommand 1653 1661 +8 doCommands 2233 2222 -11 run_applet_and_exit 128 100 -28 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 6/4 up/down: 104/-52) Total: 52 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01claenups for previous commitDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-01ash: allow shell scripts to be embedded in the binaryDenys Vlasenko
To assist in the deployment of shell scripts it may be convenient to embed them in the BusyBox binary. 'Embed scripts in the binary' takes any files in the directory 'embed', concatenates them with null separators, compresses them and embeds them in the binary. When scripts are embedded in the binary, scripts can be run as 'busybox SCRIPT [ARGS]' or by usual (sym)link mechanism. embed/nologin is provided as an example. function old new delta packed_scripts - 123 +123 unpack_scripts - 87 +87 ash_main 1103 1171 +68 run_applet_and_exit 78 128 +50 get_script_content - 32 +32 script_names - 10 +10 expmeta 663 659 -4 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 2/1 up/down: 370/-4) Total: 366 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> 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-05ash: exec: Return 126 on most errors in shellexecDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:37 +0800 exec: Return 126 on most errors in shellexec Currently when shellexec fails on most errors the shell will exit with exit status 2. This patch changes it to 126 in order to avoid ambiguities with the exit status from a successful exec. The errors that result in 127 has also been expanded to include ENOTDIR, ENAMETOOLONG and ELOOP. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta shellexec 245 254 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: eval: Restore input files in evalcommandDenys Vlasenko
Upstream commit: Date: Tue, 27 Mar 2018 00:39:35 +0800 eval: Restore input files in evalcommand When evalcommand invokes a command that modifies parsefile and then bails out without popping the file, we need to ensure the input file is restored so that the shell can continue to execute. Reported-by: Martijn Dekker <martijn@inlv.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta unwindfiles - 20 +20 evalcommand 1635 1653 +18 getoptscmd 584 595 +11 popallfiles 20 10 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 49/-10) Total: 39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash: parser: Fix parsing of ${}Denys Vlasenko
Upstream commit: Date: Tue, 3 Apr 2018 00:40:25 +0800 parser: Fix parsing of ${} dash -c 'echo ${}' should print "Bad subtitution" but instead fails with "Syntax error: Missing '}'". This is caused by us reading an extra character beyond the right brace. This patch fixes it so that this construct only fails during expansion rather than during parsing. Fixes: 3df3edd13389 ("[PARSER] Report substition errors at...") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta readtoken1 2907 2916 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05ash,hush: fold shell_builtin_read() way-too-many params into a struct paramDenys Vlasenko
function old new delta getoptscmd 587 584 -3 readcmd 240 224 -16 shell_builtin_read 1426 1399 -27 builtin_read 210 182 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-74) Total: -74 bytes 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: var: Set IFS to fixed value at start timeDenys Vlasenko
Upstream commit: Date: Sat, 19 May 2018 02:39:43 +0800 var: Set IFS to fixed value at start time This patch forces the IFS variable to always be set to its default value, regardless of the environment. It also removes the long unused IFS_BROKEN code. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 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-24hush: add "heredoc.tests" from ash, tweak ash "is a function" messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-14ash: expand: Fix buffer overflow in expandmetaDenys Vlasenko
Upstream commit: Date: Sun, 25 Mar 2018 16:38:00 +0800 expand: Fix buffer overflow in expandmeta The native version of expandmeta allocates a buffer that may be overrun for two reasons. First of all the size is 1 byte too small but this is normally hidden because the minimum size is rounded up to 2048 bytes. Secondly, if the directory level is deep enough, any buffer can be overrun. This patch fixes both problems by calling realloc when necessary. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> function old new delta expmeta 517 635 +118 expandarg 990 996 +6 mklocal 288 290 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 126/0) Total: 126 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11ash: parser: Allow newlines within parameter substitutionDenys Vlasenko
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>
2018-04-11hush: do not drop backslash from eval 'echo ok\'Denys Vlasenko
newer bash does not drop it, most other shells too function old new delta unbackslash 39 57 +18 parse_stream 2753 2751 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-2) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10shell: add comments about [[, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-10ash: if "[[" bashism is not supported, do not handle it anywhereDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>