aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * hush: fix handling of by backslash-newline in $((arith)) and $(cmd)Denys Vlasenko2016-09-291-15/+39
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: rework input char buffering to allow more than one-deep peekDenys Vlasenko2016-09-291-68/+125
| | | | | | | | | | | | ...this time with actual hush.c changes too :) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix arithmetic closing )) split by backslash-newlineDenys Vlasenko2016-09-295-1/+50
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [PARSER] Handle backslash newlines properly after dollar signDenys Vlasenko2016-09-291-15/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes var_unbackslash1.tests failure. Upstream commit: [PARSER] Handle backslash newlines properly after dollar sign On Tue, Aug 26, 2014 at 12:34:42PM +0000, Eric Blake wrote: > On 08/26/2014 06:15 AM, Oleg Bulatov wrote: > > While playing with sh generators I found that dash and bash have different > > interpretations for <slash><newline> sequence. > > > > $ dash -c 'EDIT=xxx; echo $EDIT\ > >> OR' > > xxxOR > > Buggy. > > > > $ dash -c 'echo "$\ > > (pwd)"' > > $(pwd) > > > > Is it undefined behaviour in POSIX? > > No, it's well-defined, and dash is buggy. ... I agree. This patch should resolve this problem and similar ones affecting blackslash newlines after we encounter a dollar sign. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: rework input char buffering to allow more than one-deep peekDenys Vlasenko2016-09-2910-0/+177
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: input: Allow two consecutive calls to pungetcDenys Vlasenko2016-09-291-34/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: input: Allow two consecutive calls to pungetc The commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ([PARSER] Handle backslash newlines properly after dollar sign) created cases where we make two consecutive calls to pungetc. As we don't explicitly support that there are corner cases where you end up with garbage input leading to undefined behaviour. This patch adds explicit support for two consecutive calls to pungetc. Reported-by: Jilles Tjoelker <jilles@stack.nl> Reported-by: Juergen Daubert <jue@jue.li> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> In bbox case, bashism >& may need two pungetc() too. function old new delta pgetc 514 555 +41 pushstring 114 144 +30 basepf 52 76 +24 popstring 134 151 +17 parse_command 1584 1585 +1 pungetc 12 9 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/1 up/down: 113/-3) Total: 110 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix 'eval ""' handlingDenys Vlasenko2016-09-295-1/+15
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix ". EMPTY_LINE" not setting $? to 0Denys Vlasenko2016-09-295-0/+18
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: jobs: Don't attempt to access job table for job %0Denys Vlasenko2016-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: jobs: Don't attempt to access job table for job %0 If job %0 is (mistakenly) specified, an out-of-bounds access to the jobtab occurs in function getjob() if num = 0: jp = jobtab + 0 - 1 Fix this by checking that the job number is larger than 0 before accessing the jobtab. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [EVAL] Make eval with empty arguments return 0Denys Vlasenko2016-09-295-36/+36
| | | | | | | | | | | | | | | | This is a backport of upstream commit: [EVAL] Make eval with empty arguments return 0 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [EVAL] Fix use-after-free in dotrap/evalstringDenys Vlasenko2016-09-281-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From upstream: [EVAL] Fix use-after-free in dotrap/evalstring The function dotrap calls evalstring using the stored trap string. If evalstring then unsets that exact trap string then we will end up using freed memory. This patch fixes it by making evalstring always duplicate the string before using it. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: Remove unused EV_BACKCMD flagDenys Vlasenko2016-09-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | The original ash defered forking commands in backquotes so builtins could be run in the same context as the shell. This behavior was controlled using the EV_BACKCMD to evaltree. Unfortunately, as Matthias Scheler noticed in 1999 (NetBSD PR/7814), the result was counterintuitive; for example, echo "`cd /`" would change the cwd. So ash 0.3.5 left out that optimization. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: eval: Return status in eval functionsDenys Vlasenko2016-09-285-55/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backported from dash: eval: Return status in eval functions The exit status is currently clobbered too early for case statements and loops. This patch fixes it by making the eval functions return the current exit status and setting them in one place -- evaltree. Harald van Dijk pointed out a number of bugs in the original patch. function old new delta evalcommand 1226 1242 +16 cmdloop 383 398 +15 evalfor 223 227 +4 evalcase 271 275 +4 localcmd 348 350 +2 evaltreenr 927 928 +1 evaltree 927 928 +1 evalsubshell 150 151 +1 evalpipe 356 357 +1 parse_command 1585 1584 -1 evalloop 177 164 -13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 9/2 up/down: 45/-14) Total: 31 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: in heredoc code, fix access past the end of allocated memory. Closes 9276Denys Vlasenko2016-09-251-14/+18
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286Denys Vlasenko2016-09-253-5/+29
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: use glob() from libcDenys Vlasenko2016-09-211-11/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adapted from dash. The "homegrown" glob code is retained (ifdef'ed out). This changes was inspired by bug 9261, which detected out-of bounds use of heap for 2098 byte long name in the "homegrown" code. This is still not fixed... function old new delta expandarg 960 982 +22 static.syntax_index_table 26 25 -1 static.spec_symbls 27 26 -1 static.metachars 4 - -4 addfname 42 - -42 msort 126 - -126 expmeta 528 - -528 ------------------------------------------------------------------------------ (add/remove: 0/4 grow/shrink: 1/2 up/down: 22/-702) Total: -680 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix handling of bashism $'xxx' with high-bit chars. Closes 9236Denys Vlasenko2016-09-201-0/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: document better where bad redirect syntax is detectedDenys Vlasenko2016-09-201-3/+20
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: exit after subshell error when errexit option is setRostislav Skudnov2016-09-173-0/+8
| | | | | | | | | | | | | | | | | | | | | | When "set -e" option is on, shell must exit when any command fails, including compound commands of the form (compound-list) executed in a subshell. Bash and dash shells have this behaviour. Also add a corresponding testcase. Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * fix "aloc" -> "alloc" typosDenys Vlasenko2016-09-171-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: add a FIXME for bug 9246Denys Vlasenko2016-09-171-0/+9
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: placate some compile warnings on OSXDenys Vlasenko2016-09-011-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix "redirects can close script fd" bugDenys Vlasenko2016-08-223-61/+170
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: do not leak script fds into NOEXEC childrenDenys Vlasenko2016-08-201-10/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We set all opened script fds to CLOEXEC, thus making then go away after fork+exec. Unfortunately, CLOFORK does not exist. NOEXEC children will still see those fds open. For one, "ls" applet is NOEXEC. Therefore running "ls -l /proc/self/fd" in a script from standalone shell shows this: lrwx------ 1 root root 64 Aug 20 15:17 0 -> /dev/pts/3 lrwx------ 1 root root 64 Aug 20 15:17 1 -> /dev/pts/3 lrwx------ 1 root root 64 Aug 20 15:17 2 -> /dev/pts/3 lr-x------ 1 root root 64 Aug 20 15:17 3 -> /path/to/top/level/script lr-x------ 1 root root 64 Aug 20 15:17 4 -> /path/to/sourced/SCRIPT1 ... with as many open fds as there are ". SCRIPTn" nest levels. Fix it by closing these fds after fork (only for NOEXEC children). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: bit better comments in redirect code. No logic changesDenys Vlasenko2016-08-201-11/+38
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: `cmd` and arithmetic also need the fix for FILE rewindDenys Vlasenko2016-08-191-32/+39
| | | | | | | | | | | | Discovered by running testsuite with a newest glibc Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186Denys Vlasenko2016-08-192-4/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Run this in a "sh SCRIPT": sha256sum /dev/null echo END sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s. By this time, entire script is read, and buffered in a FILE object from fopen("SCRIPT"). But fgetc() did not consume entire input. exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'. (this may be libc-specific). This change of fd position *is shared with the parent*! Now parent can read more, and it thinks there is another "echo END". End result: two "echo END"s are run. Fix this by _exit()ing instead. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix handling of ${VAR: -2}Denys Vlasenko2016-07-253-4/+25
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * config: disentangle PREFER_APPLETS from SH_STANDALONE and SH_NOFORKDenys Vlasenko2016-07-221-2/+2
| | | | | | | | | | | | | | | | On user request. I thought enabling/disabling them all together is more consistent. Evidently, some people do want them to be separately selectable. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix a possible bugDenys Vlasenko2016-07-211-1/+3
| | | | | | | | | | | | Not sure this was actually a triggerable bug, but the code looked flaky. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: do not leave SIGQUIT ignored on "exec CMD"Denys Vlasenko2016-07-163-1/+20
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: enable wait builtin commandRon Yorston2016-05-191-4/+0
| |
* | ash: use a macro to substitute waitpid_child for waitpidRon Yorston2016-05-181-4/+1
| |
* | ash: fix use of pid/handle in waitpid_childRon Yorston2016-05-181-34/+65
| | | | | | | | | | | | | | | | | | | | Previously spawn was returning a process handle which was treated as a pid in certain circumstances. This resulted in the following failing: find . -type f | sed xargs -n 1 sed -n '1 p' It should output the first line of each file but stopped after the first.
* | win32: adjustments to spawn functionsRon Yorston2016-05-181-2/+1
| | | | | | | | | | | | | | | | Make mingw_spawn_applet and mingw_spawn_1 static. The return value from spawnve is an exit code in synchronous mode and a process handle in asynchronous mode. Pass these upwards without interpretation.
* | Merge branch 'busybox' into mergeRon Yorston2016-05-166-6/+13
|\|
| * *: slap on a few ALIGN1/2s where appropriateDenys Vlasenko2016-04-222-4/+4
| | | | | | | | | | | | | | | | | | | | The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map" text data bss dec hex filename 829901 4086 1904 835891 cc133 busybox_before 829665 4086 1904 835655 cc047 busybox Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: bash-compatible $'...' shouldn't expand in double quotesRon Yorston2016-04-155-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bash doesn't expand its $'...' construct in double quotes: $ echo "$'a\tb'" $'a\tb' Change BusyBox ash to do the same. This also fixes a problem with here documents where BusyBox ash gave an incorrect result for: $ cat <<EOF > '$' > EOF '$' Reported-by: Timo Teras <timo.teras@iki.fi> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Rewrite iteration through applet names to save a few bytesRon Yorston2016-04-151-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta run_applet_and_exit 758 755 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3) Total: -3 bytes In standalone shell mode the saving increases to 17 bytes. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: adjustment to 'busybox' command in standalone shell modeRon Yorston2016-04-221-19/+5
| | | | | | | | | | | | | | | | | | | | A previous change allowed the command 'busybox' (which isn't an applet) to be invoked by a direct call to the executable, avoiding a PATH lookup. For some reason I also checked that the name of the executable was 'busybox.exe'. This seems unnecessary and prevents the trick from working when the binary is called 'sh.exe', so don't do it any more.
* | ash: improve handling of invalid environment variable namesRon Yorston2016-04-051-6/+6
| | | | | | | | | | | | | | The code to replace invalid characters in environment variable names was being invoked unconditionally because the value of 'end' was altered in the loop to replace backslashes. Avoid this by using a separate loop variable.
* | Merge branch 'busybox' into mergeRon Yorston2016-04-045-0/+13
|\|
| * ash_test: ignore generated filesMike Frysinger2016-03-221-0/+7
| | | | | | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>
| * ash_test: printenv: fix missing includesMike Frysinger2016-03-221-0/+1
| | | | | | | | Signed-off-by: Mike Frysinger <vapier@gentoo.org>
| * ash: fix corruption of ${#var} if $var contains UTF-8 charactersRon Yorston2016-03-223-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As reported in bug 8506: $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz $ echo ${#X} abcd26 The result should be 26. This regression was introduced by: <d68d1fb> 2015-05-18 [Ron Yorston] ash: code shrink around varvalue The length in characters was being used to discard the contents of the variable instead of the length in bytes. URL: https://bugs.busybox.net/8506 Reported-by: Martijn Dekker <martijn@inlv.org> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* | Merge branch 'busybox' into mergeRon Yorston2016-02-221-2/+1
|\|
| * Fix compiling with musl's utmp stubsKylie McClain2016-02-011-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes compiling busybox with FEATURE_UTMP and _WTMP enabled. musl, while not really support utmp/wtmp, provides stub functions, as well as variables such as _PATH_UTMP, so that programs using utmp or wtmp can still compile fine. My reasoning for this patch is that on Exherbo, I'm currently trying to get us to be able to use the same busybox config file for both glibc and musl systems, using utmp/wtmp on systems that support it, and using the stubs on musl without needing two different configs. As of latest musl git, it provides all utmp functions needed; 1.1.12 doesn't, but I sent a patch to Rich to add the utmp{,x}name functions expected to exist, which was merged into musl upstream. Signed-off-by: Kylie McClain <somasissounds@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: suppress a compilation warningCristian Ionescu-Idbohrn2016-01-021-1/+1
| | | | | | | | | | | | | | | | | | | | Reported by gcc (Debian 5.3.1-4) 5.3.1 20151219 shell/ash.c: In function 'evaltree': shell/ash.c:8432:19: warning: logical not is only applied to the left hand side of comparison Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2015-11-0620-33/+228
|\|
| * ash: add support for bash 'function' keywordRon Yorston2015-11-043-31/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Where the POSIX shell allows functions to be defined as: name () compound-command [ redirections ] bash adds the alternative syntax: function name [()] compound-command [ redirections ] Implement this in ash's bash compatibility mode. Most compound commands work (for/while/until/if/case/[[]]/{}); one exception is: function f (echo "no way!") The other two variants work: f() (echo "ok") function f() (echo "also ok") function old new delta parse_command 1555 1744 +189 tokname_array 232 240 +8 .rodata 155612 155566 -46 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 197/-46) Total: 151 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>