Ron Yorston [Thu, 20 Oct 2016 11:24:02 +0000 (12:24 +0100)]
ash: return exit status of nofork applets
The commit 'ash: eval: Return status in eval functions' changed how
exit status is handled in eval functions. The case of nofork
applets was missed, resulting in the incorrect status potentially
being returned for nofork applets when FEATURE_SH_NOFORK is enabled.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 14 Oct 2016 17:02:11 +0000 (19:02 +0200)]
examples: update var_service/README again
Added "ps -AH e" example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 14 Oct 2016 16:48:05 +0000 (18:48 +0200)]
typo fixes in doc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 14 Oct 2016 16:38:08 +0000 (18:38 +0200)]
examples: update var_service/README again
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 14 Oct 2016 16:22:50 +0000 (18:22 +0200)]
examples: update var_service/README
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 13 Oct 2016 14:17:06 +0000 (16:17 +0200)]
telnetd: ifdef out a buggy error handling code path
Here, not handling the error is would just eat one input 0xff char.
Correct handling would need even more corner case handling,
as-is buggy handling corrupts the buffer.
Since we just been told by kernel that pty is ready,
EAGAIN should not be happening here anyway.
function old new delta
telnetd_main 1798 1785 -13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 18:56:46 +0000 (20:56 +0200)]
cpio: fix restoration of file ownership, closes 9306
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 18:42:58 +0000 (20:42 +0200)]
telnet: code shrink
put_iac2(w,c) is mostly used with constants, fold them into one arg
function old new delta
put_iac2_merged - 46 +46
telnet_main 1603 1583 -20
con_escape 285 257 -28
put_iac2 50 - -50
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 46/-98) Total: -52 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 18:09:22 +0000 (20:09 +0200)]
telnetd: add another handshake example in comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 17:41:33 +0000 (19:41 +0200)]
telnetd: treat all 2-byte IACs in 240..249 range as NOPs.
A bit of future-proofing. Some of them can stand just being ignored.
function old new delta
telnetd_main 1791 1798 +7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 17:13:46 +0000 (19:13 +0200)]
telnetd: fix corner case of input processing of 0xff bytes
I managed to reproduce the bug, with some difficulty.
function old new delta
telnetd_main 1780 1791 +11
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 15:36:57 +0000 (17:36 +0200)]
telnetd: fix a corner case where CRLF->CR translation can misbehave
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 12 Oct 2016 12:54:10 +0000 (14:54 +0200)]
telnetd: fix handling of short writes to pty
If a write to pty is short, remove_iacs() can be run on a buffer repeatedly.
This, for example, can eat 0xff chars (IACs, in telnet terms).
Rework the logic to handle IACs in a special "write to pty" function.
function old new delta
telnetd_main 1662 1750 +88
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Tue, 11 Oct 2016 13:29:38 +0000 (15:29 +0200)]
more: accept and ignore a bunch of options
Alpine Linux stumbled over "more -s":
http://bugs.alpinelinux.org/issues/5190
function old new delta
more_main 857 872 +15
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 9 Oct 2016 21:04:16 +0000 (23:04 +0200)]
ifupdown: rewrite state file atomically
By user's request.
Decided to not use fcntl(F_SETLKW) in lieu of problems with locking
on networked filesystems. The existence of /var/run/ifstate.new
is treated as a write lock. rename() provides atomicity.
function old new delta
ifupdown_main 1019 1122 +103
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 7 Oct 2016 13:56:47 +0000 (15:56 +0200)]
tcpsvd: don't keep shared fd open if fd limit is reached. closes 9331
Also, much improved help text.
function old new delta
packed_usage 30652 30851 +199
tcpudpsvd_main 1782 1784 +2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 7 Oct 2016 02:28:33 +0000 (04:28 +0200)]
ash: all blocks in function node copying must be SHELL_ALIGNed
Previous commit probably introduced a bug:
non-matching size calculation in size counting and
actual copying caused by SHELL_ALIGN being applied differently!
This won't bite if string sizes are also SHELL_ALIGNed.
Thus fixing.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 7 Oct 2016 02:07:05 +0000 (04:07 +0200)]
ash testsuite: fix false positives
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 7 Oct 2016 02:05:15 +0000 (04:05 +0200)]
ash: get rid of two global data variables
function old new delta
calcsize 126 147 +21
funcstring_end - 4 +4
sizenodelist 28 24 -4
funcstringsize 4 - -4
funcstring 4 - -4
funcblocksize 4 - -4
nodeckstrdup 48 39 -9
evaltree 828 788 -40
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 1/4 up/down: 25/-105) Total: -40 bytes
text data bss dec hex filename
943376 916 14292 958584 ea078 busybox_old
943344 916 14284 958544 ea050 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 7 Oct 2016 01:17:28 +0000 (03:17 +0200)]
ash: comment out free(p) just before _exit, tweak some outdated comments
Planned to sync exitshell up to dash, turned out ours is better :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Tue, 4 Oct 2016 02:23:09 +0000 (04:23 +0200)]
wget: there is no -s option in GNU Wget 1.18, we should be compatible
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 22:51:38 +0000 (00:51 +0200)]
dhcp: merge leases.c and static_leases.c into dhcpd.c
function old new delta
send_offer 292 461 +169
udhcpd_main 1531 1588 +57
read_leases 330 332 +2
add_lease 314 312 -2
find_lease_by_mac 68 - -68
find_free_or_expired_nip 174 - -174
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 3/1 up/down: 228/-244) Total: -16 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 22:43:14 +0000 (00:43 +0200)]
dhcp: merge most of static_leases.c into dhcpd.c
function old new delta
read_staticlease 121 222 +101
add_static_lease 48 - -48
log_static_leases 68 - -68
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 101/-116) Total: -15 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 22:37:50 +0000 (00:37 +0200)]
dhcp: merge files.c into dhcpd.c
Added NOINLINE to two function, since my version of gcc would actualy increase
code size otherwise.
I see no size changes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 21:43:44 +0000 (23:43 +0200)]
examples: add example of a DHCP server
As usual, by multiplying directories - "dhcpd_eth0", "dhcpd_wlan1"
you can run many servers on different interfaces.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 15:42:53 +0000 (17:42 +0200)]
hush: add commented-out debug printouts in "memleak" built-in
Allocation addresses of malloc() are jittery,
thought I had a mem leak in hush, but it was malloc variability.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Mon, 3 Oct 2016 13:01:06 +0000 (15:01 +0200)]
hush: fix a memory corruption when exported variable is modified
The construct such as this:
t=1
export t
t=new_value1
had a small probability of momentarily using free()d value.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 23:01:15 +0000 (01:01 +0200)]
hush: fix exitcode on exec failure with EACCES - should be 126
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 22:55:34 +0000 (00:55 +0200)]
sh testsuite: add tests for exitcode on failure to exec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 22:51:29 +0000 (00:51 +0200)]
shell: delete all msh tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 22:14:26 +0000 (00:14 +0200)]
hush testsuite: fix another false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 22:10:20 +0000 (00:10 +0200)]
hust testsuite: fix a false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 22:06:55 +0000 (00:06 +0200)]
ash testsuite: add most of hust tests which pass for ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 21:47:34 +0000 (23:47 +0200)]
ash: [PARSER] Add nlprompt/nlnoprompt helpers
Upstream commit:
Date: Mon, 29 Sep 2014 22:53:53 +0800
[PARSER] Add nlprompt/nlnoprompt helpers
This patch adds the nlprompt/nlnoprompt helpers to isolate code
dealing with newlines and prompting.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 20:33:15 +0000 (22:33 +0200)]
whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 19:13:13 +0000 (21:13 +0200)]
hush: add var4.tests, var5.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 19:12:02 +0000 (21:12 +0200)]
hush: fix var3.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 16:45:09 +0000 (18:45 +0200)]
sh: do not print empty line at the end of "help" output
It's pointless.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 16:32:52 +0000 (18:32 +0200)]
sh testsuite: sync ash-redir/ and hush-redir/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 16:23:14 +0000 (18:23 +0200)]
sh testsuite: sync ash-misc/source* and hush-misc/source*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 16:17:15 +0000 (18:17 +0200)]
sh testsuite: sync ash-vars/ and hush-vars/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 16:08:04 +0000 (18:08 +0200)]
ash testsuite: update some of variable tests with newer versions from hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 15:55:51 +0000 (17:55 +0200)]
sh testsuite: create hush-redir/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 15:49:46 +0000 (17:49 +0200)]
sh testsuite: create hush-heredoc/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 15:39:31 +0000 (17:39 +0200)]
hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 14:54:17 +0000 (16:54 +0200)]
ash: undo "tokname hack"
dash has tokendlist[] array to decide which tokens end lists.
We store it as first byte of each tokname_array[i].
Switch to bit array, name it like dash (tokendlist), drop special
1st byte of tokname_array[i]. This brings us closer to dash, and
shrinks the binary, because many more string aliasing opportunities
are now open:
function old new delta
pstrcmp1 - 16 +16
readtoken1 2852 2858 +6
list 326 327 +1
pstrcmp 16 15 -1
tokname 45 42 -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 23/-4) Total: 19 bytes
text data bss dec hex filename
943556 916 14292 958764 ea12c busybox_old
943463 916 14292 958671 ea0cf busybox_unstripped
^^^^^^^ note this!
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 13:31:33 +0000 (15:31 +0200)]
ash: placate gcc: "warning: ! is only applied to the left hand side of =="
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 13:20:57 +0000 (15:20 +0200)]
hush testsuite: add glob_dir.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 13:17:15 +0000 (15:17 +0200)]
ash: fix globbing bugs when using glibc glob()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 02:38:07 +0000 (04:38 +0200)]
ash: style fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 01:16:00 +0000 (03:16 +0200)]
ash: support "--" in "source" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sun, 2 Oct 2016 00:46:56 +0000 (02:46 +0200)]
ash: expand: Fixed "$@" expansion when EXP_FULL is false
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>
Denys Vlasenko [Sun, 2 Oct 2016 00:35:13 +0000 (02:35 +0200)]
test: fix compile error in last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 23:49:13 +0000 (01:49 +0200)]
test: memory leak: free group id list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 21:28:02 +0000 (23:28 +0200)]
ash,hush: add a test that "continue" does not cripple traps
Both shells pass this test.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 21:25:12 +0000 (23:25 +0200)]
ash: fix return_in_trap1.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 20:36:14 +0000 (22:36 +0200)]
ash testsuite: add return_in_trap1.tests
Currently it fails
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 20:28:03 +0000 (22:28 +0200)]
hush: 'return' should have effect earlier
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 19:02:06 +0000 (21:02 +0200)]
ash: [EXPAND] Optimise nulonly away and just use quoted as before
Upstream commit:
Date: Wed, 8 Oct 2014 20:09:56 +0800
[EXPAND] Optimise nulonly away and just use quoted as before
This patch makes a small optimisation by using the same value for
quoted between evalvar and varvalue by eliminating nulonly and
passing along quoted instead.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 18:55:02 +0000 (20:55 +0200)]
ash: [EXPAND] Do not split quoted VSLENGTH and VSTRIM
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>
Denys Vlasenko [Sat, 1 Oct 2016 18:35:10 +0000 (20:35 +0200)]
ash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
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>
Denys Vlasenko [Sat, 1 Oct 2016 18:12:10 +0000 (20:12 +0200)]
hush: add func6.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 17:56:52 +0000 (19:56 +0200)]
ash: fix "return N" not setting $? in loop conditionals
Upstream commit 1:
Date: Mon, 6 Oct 2014 20:45:04 +0800
[EVAL] Move common skipcount logic into skiploop
The functions evalloop and evalfor share the logic on checking
and updating skipcount. This patch moves that into the helper
function skiploop.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:
Date: Mon, 6 Oct 2014 21:22:43 +0800
[BUILTIN] Allow return in loop conditional to set exit status
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332954
When return is used in a loop conditional the exit status will
be lost because we always set the exit status at the end of the
loop to that of the last command executed in the body.
This is counterintuitive and contrary to what most other shells do.
This patch fixes this by always preserving the exit status of
return when it is used in a loop conditional.
The patch was originally written by Gerrit Pape <pape@smarden.org>.
Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 15:43:04 +0000 (17:43 +0200)]
ash testsuite: remove two more inadvertent bashisms
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 15:30:21 +0000 (17:30 +0200)]
ash testsuite: remove two inadvertent bashisms
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 14:03:11 +0000 (16:03 +0200)]
ash: [ERROR] Set exitstatus in onint
Partially backported this commit:
Date: Thu, 2 Oct 2014 21:07:55 +0800
[ERROR] Set exitstatus in onint
Currently the exit status when we receive SIGINT is set in evalcommand
which means that it doesn't always get set. For example, if you press
CTRL-C at the prompt of an interactive dash, the exit status is not
set to 130 as it is in many other Bourne shells.
This patch fixes this by moving the setting of the exit status into
onint which also simplifies evalcommand.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
The part after "if (evalbltin(cmdentry.u.cmd, argc, argv, flags))"
causes testsuite failures in signal handling, so left unchanged.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 13:27:44 +0000 (15:27 +0200)]
ash: [EVAL] Revert SKIPEVAL into EXEXIT
Upstream commit:
Date: Tue Aug 11 20:56:53 2009 +1000
[EVAL] Revert SKIPEVAL into EXEXIT
Now that eval handles EV_TESTED correctly, we can remove the
SKIPEVAL hack and simply use EXEXIT for set -e.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 13:10:16 +0000 (15:10 +0200)]
ash: [EVAL] Pass EV_TESTED into evalcmd
Upstream commit:
Date: Tue Aug 11 20:48:15 2009 +1000
[EVAL] Pass EV_TESTED into evalcmd
This patch fixes the case where the eval command is used with
set -e and as part of a construct that should not cause the
shell to abort, e.g., as part of the condition of an if statement.
This is achieved by propagating the EV_TESTED flag into the
evalstring function through evalcmd. As this alters the prototype
of evalcmd it is now invoked explicitly by evalbltin. The built-in
infrastructure has been changed to accomodate this special case.
In order to ensure that the EXIT trap is properly executed this
patch clears evalskip in exitshell. This wasn't needed before
because of the broken way evalstring worked where it always clears
evalskip when called by minusc.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Although, I failed to create a reproducer for this.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 12:47:52 +0000 (14:47 +0200)]
ash: fix a thinko in the last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 12:33:08 +0000 (14:33 +0200)]
ash: make internal globbing code selectable from config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Sat, 1 Oct 2016 01:02:25 +0000 (03:02 +0200)]
ash: explain how "command" is handled, and shrink it a bit
function old new delta
getoptscmd 641 632 -9
commandcmd 79 69 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 12:36:59 +0000 (14:36 +0200)]
ash: [VAR] Initialise OPTIND after importing environment
Upstream commit 1:
Date: Fri, 23 Aug 2013 21:27:42 +1000
[VAR] Initialise OPTIND after importing environment
On Sat, Mar 23, 2013 at 01:46:20AM +0000, Chris F.A. Johnson wrote:
> According to both the dash man page and the POSIX spec, "When the
> shell is invoked, OPTIND is initialized to 1."
>
> However, it actually takes the value of the environment variable
> if it exists:
>
> $ OPTIND=4 dash -c 'echo "$OPTIND"'
> 4
> $ OPTIND=4 bash -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
> 1
This patch fixes this by initialising OPTIND after importing the
environment.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:
Date: Tue, 7 Oct 2014 22:24:42 +0800
[VAR] Use setvareq to set OPTIND initially
There is no need to setvarint to set the initial value of OPTIND
of one. This patch switchs to setvareq which also lets us avoid
an unnecessary memory allocation.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 12:18:34 +0000 (14:18 +0200)]
ash: [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd
Upstream commit:
Date: Sat, 9 Jul 2011 22:05:22 +0800
[BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd
Currently upon leaving a dotcmd the evalskip state is reset so
if a continue/break statement is used within a dot script it would
have no effect outside of the dot script.
This is inconsistent with other shells.
This patch is based on one by Jilles Tjoelker and only clears
SKIPFUNC when leaving a dot script. As a result continue/break
will remain in effect.
It also merges SKIPFUNC/SKIPFILE as they have no practical difference.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 10:28:37 +0000 (12:28 +0200)]
hush: enable "msh is deprecated" message in msh stub
After giving a few more years for everyone to notice and migrate,
can nuke all remains of msh.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 09:35:54 +0000 (11:35 +0200)]
ash: Avoid overflow for very long variable name
Upstream commit:
Date: Tue, 3 Jul 2012 17:32:33 +0800
Avoid overflow for very long variable name
Otherwise, this:
$ perl -le 'print "v"x(2**31+1) ."=1"' | dash
provokes integer overflow
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 09:33:47 +0000 (11:33 +0200)]
ash: [VAR] Sanitise environment variable names on entry
Upstream commit:
Date: Sat, 25 Feb 2012 15:35:18 +0800
[VAR] Sanitise environment variable names on entry
On Tue, Feb 14, 2012 at 10:48:48AM +0000, harald@redhat.com wrote:
> "export -p" prints all environment variables, without checking if the
> environment variable is a valid dash variable name.
>
> IMHO, the only valid usecase for "export -p" is to eval the output.
>
> $ eval $(export -p); echo OK
> OK
>
> Without this patch the following test does error out with:
>
> test.py:
> import os
> os.environ["test-test"]="test"
> os.environ["test_test"]="test"
> os.execv("./dash", [ './dash', '-c', 'eval $(export -p); echo OK' ])
>
> $ python test.py
> ./dash: 1: export: test-test: bad variable name
>
> Of course the results can be more evil, if the environment variable
> name is crafted, that it injects valid shell code.
This patch fixes the issue by sanitising all environment variable names
upon entry into the shell.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 09:30:11 +0000 (11:30 +0200)]
ash: [EVAL] Avoid using undefined handler
Upstream commit:
Date: Fri, 8 Jul 2011 16:41:24 +0800
[EVAL] Avoid using undefined handler
* src/eval.c (evalbltin, evalfun): Set savehandler before calling
setjmp with the possible "goto *done", where savehandler is used.
Otherwise, clang warns that "Assigned value is garbage or undefined"
at the point where "savehandler" is used on the RHS.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 09:24:12 +0000 (11:24 +0200)]
ash: remove dead stores and unused variables
Upstream commit 1:
Date: Fri, 8 Jul 2011 16:12:20 +0800
[MEMALLOC] Avoid gcc warning: variable 'oldstackp' set but not used
* src/memalloc.c (growstackblock): Remove declaration and set of
set-but-not-used variable. Also remove a stray space-before-TAB.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Upstream commit 2:
Date: Fri, 8 Jul 2011 16:16:11 +0800
[MEMALLOC] Avoid clang warning about dead store to "size"
* src/memalloc.c (makestrspace): Remove dead store.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 09:21:21 +0000 (11:21 +0200)]
ash: [MEMALLOC] Add pushstackmark
Upstream commit:
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date: Sat Oct 6 00:45:52 2007 +0800
[MEMALLOC] Add pushstackmark
This patch gets rid of the stack mark tracking hack by allocating a little
bit of stack memory if we're at risk of planting a stack mark which may be
grown later. To do this a new function pushstackmark is added which lets
the user pick a bigger amount to allocate since some users do that anyway
after setting a stack mark.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Fri, 30 Sep 2016 00:02:25 +0000 (02:02 +0200)]
hush: fix typo in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 23:49:53 +0000 (01:49 +0200)]
hush: fix interactive input handling of backslash+newline
function old new delta
fgetc_interactive - 258 +258
i_peek_and_eat_bkslash_nl 43 93 +50
static_peek2 7 - -7
setup_string_in_str 46 39 -7
setup_file_in_str 47 40 -7
file_peek 72 52 -20
expand_vars_to_list 1167 1143 -24
file_peek2 74 - -74
file_get 326 65 -261
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/5 up/down: 308/-400) Total: -92 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 18:25:44 +0000 (20:25 +0200)]
hush: G.user_input_buf[] is needed only if line editing is enabled
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 18:02:53 +0000 (20:02 +0200)]
shell testsuite: add trailing newline to var_unbackslash1.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 17:50:55 +0000 (19:50 +0200)]
hush: speed optimizations
Make o_addchr() faster: do not call o_grow_by() each time.
Create i_getch_and_eat_bkslash_nl(), use it instead of peek+getch pair.
function old new delta
o_addchr 42 54 +12
parse_dollar 761 771 +10
o_grow_by 48 37 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 24/-11) Total: 11 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 16:07:42 +0000 (18:07 +0200)]
hush: fix handling of by backslash-newline in $((arith)) and $(cmd)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 16:02:37 +0000 (18:02 +0200)]
hush: rework input char buffering to allow more than one-deep peek
...this time with actual hush.c changes too :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 15:58:58 +0000 (17:58 +0200)]
ash: fix arithmetic closing )) split by backslash-newline
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Thu, 29 Sep 2016 15:17:04 +0000 (17:17 +0200)]
ash: [PARSER] Handle backslash newlines properly after dollar sign
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>
Denys Vlasenko [Thu, 29 Sep 2016 14:59:06 +0000 (16:59 +0200)]
hush: rework input char buffering to allow more than one-deep peek
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>
Denys Vlasenko [Thu, 29 Sep 2016 00:11:19 +0000 (02:11 +0200)]
ash: input: Allow two consecutive calls to pungetc
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>
Denys Vlasenko [Wed, 28 Sep 2016 23:44:17 +0000 (01:44 +0200)]
hush: fix 'eval ""' handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 28 Sep 2016 23:27:09 +0000 (01:27 +0200)]
hush: fix ". EMPTY_LINE" not setting $? to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 28 Sep 2016 23:10:08 +0000 (01:10 +0200)]
ash: jobs: Don't attempt to access job table for job %0
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>
Denys Vlasenko [Wed, 28 Sep 2016 22:30:31 +0000 (00:30 +0200)]
ash: [EVAL] Make eval with empty arguments return 0
This is a backport of upstream commit:
[EVAL] Make eval with empty arguments return 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 28 Sep 2016 21:02:57 +0000 (23:02 +0200)]
ash: [EVAL] Fix use-after-free in dotrap/evalstring
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>
Denys Vlasenko [Wed, 28 Sep 2016 17:44:16 +0000 (19:44 +0200)]
ash: Remove unused EV_BACKCMD flag
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>
Denys Vlasenko [Wed, 28 Sep 2016 17:41:57 +0000 (19:41 +0200)]
ash: eval: Return status in eval functions
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>
Denys Vlasenko [Wed, 28 Sep 2016 16:39:06 +0000 (18:39 +0200)]
traceroute: cleanup and fixes for packet size calculations
Remove FEATURE_TRACEROUTE_SOURCE_ROUTE: it's off by default, and
source routing is not used in real world.
Tested that "traceroute -n ::1 100" and "traceroute -n 127.0.0.1 100"
both send 100 byte IP packets (this matches what traceroute on Fedora
Rawhide is doing).
function old new delta
common_traceroute_main 3731 3738 +7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Wed, 28 Sep 2016 14:23:05 +0000 (16:23 +0200)]
vi: fix '' command (goto to prev context)
The '' command in vi doesn't currently work because after the first
apostrophe is read, the next character is converted to an integer
between 0 and 25 inclusive (for indexing the array of marks). The
comparison of the converted character with an apostrophe therefore never
succeeds, meaning that '' doesn't do anything.
Based on the patch by Francis Rounds <francis.rounds@4bridgeworks.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko [Tue, 27 Sep 2016 19:02:35 +0000 (21:02 +0200)]
mount: for cifs, dont insert "ip=ADDR" option if user gave it explicitly
This makes it possible to use scoped IPv6 addresses:
mount -t cifs -o ip=<ADDR>%<iface_id> //<ADDR>/test test
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>