Commit 64f70cc755 (Add --login support) added code in options()
to handle the bash-compatible '--login' option. In doing so it
committed BusyBox ash to silently accepting all other long
options.
Restore compatibility with other ash variants by rejecting unknown
long options.
function old new delta
options 589 624 +35
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
dash has accepted a patch to remove the first argument of findvar().
It's commit e85e972 (var: move hashvar() calls into findvar()).
Apply the same change to BusyBox ash.
function old new delta
findvar 35 40 +5
mklocal 268 261 -7
exportcmd 164 157 -7
setvareq 319 310 -9
lookupvar 150 141 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32) Total: -27 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
"echo text >&0000000000002" works as you would expect,
"echo text >&9999999999" properly fails instead of creating a file
named "9999999999".
function old new delta
expredir 219 232 +13
readtoken1 3045 3053 +8
parsefname 204 201 -3
isdigit_str9 45 - -45
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 21/-48) Total: -27 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
With very large fd#, the error code path is different
from one for closed but small fd#.
Make it not abort if we are interactive:
$ echo text >&99 # this wasn't buggy
ash: dup2(9,1): Bad file descriptor
$ echo text >&9999 # this was
ash: fcntl(1,F_DUPFD,10000): Invalid argument
function old new delta
.rodata 105637 105661 +24
dup2_or_raise 35 38 +3
redirect 1084 1044 -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 27/-40) Total: -13 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Commit 549deab5a (ash: move parse-time quote flag detection to
run-time) did away with the need to distinguish between backquotes
inside and outside quotes. This left a gap among the control
characters used in argument strings. Removing this gap saves a
few bytes.
function old new delta
.rodata 167346 167338 -8
cmdputs 399 388 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
An alias expansion immediately followed by '<' and a newline is
parsed incorrectly:
~ $ alias x='echo yo'
~ $ x<
yo
~ $
sh: syntax error: unexpected newline
The echo is executed and an error is printed on the next command
submission. In dash the echo isn't executed and the error is
reported immediately:
$ alias x='echo yo'
$ x<
dash: 3: Syntax error: newline unexpected
$
The difference between BusyBox and dash is that BusyBox supports
bash-style process substitution and output redirection. These
require checking for '<(', '>(' and '&>' in readtoken1().
In the case above, when the end of the alias is found, the '<' and
the following newline are both read to check for '<('. Since
there's no match both characters are pushed back.
The next input is obtained by reading the expansion of the alias.
Once this string is exhausted the next call to __pgetc() calls
preadbuffer() which pops the string, reverts to the previous input
and recursively calls __pgetc(). This request is satisified from
the pungetc buffer. But the first __pgetc() doesn't know this:
it sees the character has come from preadbuffer() so it (incorrectly)
updates the pungetc buffer.
Resolve the issue by moving the code to pop the string and fetch
the next character up from preadbuffer() into __pgetc().
function old new delta
pgetc 28 589 +561
__pgetc 607 - -607
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 561/-607) Total: -46 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
When I planned to print the command in read_line_input, I found that after
the system started, the command printed for the first time was always
garbled.
After analysis, it is found that in the init() function of ash, the
variable basepf.buf is not initialized after applying for memory, resulting
in garbled initial data. Then assign it to the global variable
g_parsefile->buf in ash.c, and then pass g_parsefile->buf to the parameter
command of the function read_line_input in the function preadfd(), and
finally cause it to be garbled when the command is printed by
read_line_input.
The call stack is as follows:
#0 read_line_input (st=0xb6fff220, prompt=0xb6ffc910 "\\[\\033[32m\\]\\h \\w\\[\\033[m\\] \\$ ", command=command@entry=0xb6ffc230 "P\325\377\266P\325\377\266", maxsize=maxsize@entry=1024) at libbb/lineedit.c:2461
#1 0x0043ef8c in preadfd () at shell/ash.c:10812
#2 preadbuffer () at shell/ash.c:10914
#3 pgetc () at shell/ash.c:10997
#4 0x00440c20 in pgetc_eatbnl () at shell/ash.c:11039
#5 0x00440cbc in xxreadtoken () at shell/ash.c:13157
#6 0x00440f40 in readtoken () at shell/ash.c:13268
#7 0x00441234 in list (nlflag=nlflag@entry=1) at shell/ash.c:11782
#8 0x004420e8 in parsecmd (interact=<optimized out>) at shell/ash.c:13344
#9 0x00442c34 in cmdloop (top=top@entry=1) at shell/ash.c:13549
#10 0x00444e4c in ash_main (argc=<optimized out>, argv=0x444e4c <ash_main+1328>) at shell/ash.c:14747
#11 0x00407954 in run_applet_no_and_exit (applet_no=9, name=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1024
#12 0x00407b68 in run_applet_and_exit (name=0xbefffe56 "ash", argv=0x9) at libbb/appletlib.c:1047
#13 0x00407f88 in main (argc=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1181
Fixes: 82dd14a510 ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN")
Signed-off-by: zhuyan <zhuyan34@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Has a few annoying problems:
* sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell.
* sleep_for_duration() in sleep_main() has to be interruptible for
^C traps to work, which may be a problem for other users
of sleep_for_duration().
* BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it
as well (try "/bin/sleep 1 & sleep 10").
* sleep_main() must not allocate anything as ^C in ash longjmp's.
(currently, allocations are only on error paths, in message printing).
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
We risk exhaust stack with alloca() with old code.
function old new delta
arith_apply 990 1023 +33
evaluate_string 1467 1494 +27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0) Total: 60 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>