| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When the busybox is used as /sbin/init and the inittab file contains
below:
::respawn:-/bin/sh
/sbin/init spawns hush for the first time with the argv[0] contains '-',
and hush treats it as login shell. Then it reads /etc/profile and if
the file contains the command execution like below, it invokes hush as
login shell because the argv[0] argument is still '-/bin/sh' and reads
/etc/profile again. This will last until some failure (e.g., memory
failure) happens.
[ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ "
This commit fixes this issues by adding an offset (+1) to the
G.argv0_for_re_execing variable.
This issue happens on our out-of-tree UML (use mode linux) with nommu
configuration.
Link: https://lore.kernel.org/all/cover.1731290567.git.thehajime@gmail.com/
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This allows to simplify "which" applet code
function old new delta
find_executable 93 111 +18
which_main 191 177 -14
builtin_source 316 294 -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-36) Total: -18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
find_executable_in_PATH - 67 +67
if_command_vV_print_and_exit 114 116 +2
.rodata 105712 105710 -2
builtin_type 137 128 -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 69/-11) Total: 58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
While at it, correct "type" to skip non-executable files in PATH
function old new delta
builtin_source 211 316 +105
builtin_test 10 32 +22
hush_main 1150 1170 +20
builtin_type 122 137 +15
if_command_vV_print_and_exit 120 114 -6
find_in_path 131 - -131
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 4/1 up/down: 162/-137) Total: 25 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Testcase:
setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?'
should show that second "test -x" does not query ids again.
function old new delta
ash_main 1236 1256 +20
get_cached_euid - 19 +19
get_cached_egid - 19 +19
test_main 56 72 +16
test_exec 119 135 +16
is_in_supplementary_groups 52 57 +5
nexpr 718 702 -16
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16) Total: 79 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
test_main2 - 407 +407
testcmd 10 23 +13
test_main 418 56 -362
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 420/-362) Total: 58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
is_in_supplementary_groups 54 52 -2
nexpr 721 718 -3
test_exec 125 119 -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-11) Total: -11 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
executable
Upstream commit:
Date: Fri, 5 Apr 2024 17:55:46 +0800
exec: Check executable bit when searching path
Andrej Shadura <andrew.shadura@collabora.co.uk> wrote:
...
> https://bugs.debian.org/874264
> -------- Forwarded Message --------
> Subject: dash: 'command -v' mistakenly returns a shell script whose
> executable is not set
> Date: Mon, 04 Sep 2017 10:45:48 -0400
> From: Norman Ramsey <nr@cs.tufts.edu>
> To: Debian Bug Tracking System <submit@bugs.debian.org>
...
> I tracked a build bug in s-nail to a problem with dash. Symptom:
> building s-nail tries to run /home/nr/bin/clang, a script whose
> executable bit is not set. We tracked the problem to the result of
> running `command -v clang` with /bin/sh:
...
This is inherited from NetBSD. There is even a commented-out
block of code that tried to fix this.
Anyway, we now have faccessat so we can simply use it.
function old new delta
test_exec - 125 +125
find_command 911 918 +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 132/0) Total: 132 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 >&99
hush: dup2(99,1): Bad file descriptor
$ echo >&9999
hush: fcntl(1,F_DUPFD,10000): Invalid argument
$ echo 2>/dev/tty 10>&9999
hush: fcntl(10,F_DUPFD,10000): Invalid argument
$ still alive!_
function old new delta
static.setup_redirects 334 394 +60
.rodata 105661 105712 +51
dup_CLOEXEC 49 79 +30
save_fd_on_redirect 263 277 +14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 155/0) Total: 155 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
hush_main 1149 1150 +1
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>
|
|
|
|
|
|
|
| |
function old new delta
subevalvar 1576 1588 +12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
parse_stream 2271 2292 +21
.rodata 105408 105427 +19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0) Total: 40 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
set_G_ifs - 151 +151
run_list 1024 1031 +7
run_pipe 1567 1445 -122
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 158/-122) Total: 36 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
sleep_main 116 119 +3
printf_main 860 837 -23
single_argv 50 25 -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48) Total: -45 bytes
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: 82dd14a510ca ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN")
Signed-off-by: zhuyan <zhuyan34@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
aliascmd 274 278 +4
signal_handler 81 80 -1
static.redirectsafe 144 141 -3
unwindlocalvars 219 215 -4
trapcmd 333 329 -4
setvar 164 160 -4
setpwd 167 163 -4
setinputfile 216 212 -4
setcmd 76 72 -4
readcmd 221 217 -4
raise_exception 26 22 -4
out2str 37 33 -4
out1str 32 28 -4
freejob 89 85 -4
forkchild 616 612 -4
fg_bgcmd 298 294 -4
expandarg 949 945 -4
evaltree 753 749 -4
evalsubshell 173 169 -4
evalpipe 346 342 -4
evalfun 408 404 -4
cdcmd 699 695 -4
ash_main 1240 1236 -4
__pgetc 589 585 -4
unaliascmd 152 147 -5
unalias 51 46 -5
umaskcmd 253 248 -5
stalloc 97 92 -5
shiftcmd 144 139 -5
setinputstring 73 68 -5
redirect 1068 1063 -5
recordregion 81 76 -5
pushstring 160 155 -5
popstring 120 115 -5
popstackmark 69 64 -5
popredir 123 118 -5
popfile 110 105 -5
out1fmt 45 40 -5
newline_and_flush 39 34 -5
ifsfree 66 61 -5
growstackblock 146 141 -5
freestrings 95 90 -5
fmtstr 59 54 -5
flush_stdout_stderr 23 18 -5
dowait 577 572 -5
delete_cmd_entry 52 47 -5
clearcmdentry 98 93 -5
ash_arith 79 74 -5
argstr 1404 1399 -5
evalcommand 1523 1515 -8
removerecordregions 219 209 -10
mklocal 284 274 -10
find_command 893 883 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251) Total: -247 bytes
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>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
.rodata 105304 105261 -43
parse_command 1696 1633 -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106) Total: -106 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
builtin_readonly 61 107 +46
builtin_export 140 145 +5
.rodata 105321 105304 -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-17) Total: 34 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
arith_apply 991 1030 +39
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
parse_with_base 170 174 +4
arith_apply 996 991 -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5) Total: -1 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
arith_apply 999 996 -3
evaluate_string 1295 1291 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7) Total: -7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
arith_apply 1023 996 -27
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
arith_apply 1015 1023 +8
evaluate_string 1309 1295 -14
.rodata 105344 105321 -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37) Total: -29 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
parse_with_base - 170 +170
evaluate_string 1477 1309 -168
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168) Total: 2 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1478 1470 -8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1488 1478 -10
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1498 1491 -7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1486 1498 +12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
| |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1489 1486 -3
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>
|
|
|
|
|
|
|
| |
function old new delta
evaluate_string 1412 1467 +55
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
function old new delta
unset_local_var - 112 +112
findvar 31 35 +4
set_vars_and_save_old 144 141 -3
helper_export_local 235 230 -5
set_local_var 425 416 -9
handle_changed_special_names 38 27 -11
builtin_unset 154 141 -13
builtin_getopts 404 391 -13
get_local_var_value 281 260 -21
get_ptr_to_local_var 71 45 -26
unset_local_var_len 139 - -139
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240) Total: -124 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|