diff options
author | Hajime Tazaki <thehajime@gmail.com> | 2024-11-25 14:08:36 +0900 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-09 01:58:45 +0100 |
commit | 23db6896830d6b37fc3bcc3ad5a7f725eb97d2e1 (patch) | |
tree | 76f20faf0405da909b4647dd19cd7ba132ee4aa5 | |
parent | 75ca8d074bacb6896d770993b93161c40aa31b9f (diff) | |
download | busybox-w32-23db6896830d6b37fc3bcc3ad5a7f725eb97d2e1.tar.gz busybox-w32-23db6896830d6b37fc3bcc3ad5a7f725eb97d2e1.tar.bz2 busybox-w32-23db6896830d6b37fc3bcc3ad5a7f725eb97d2e1.zip |
hush: fix G.argv0_for_re_execing to avoid endless loop
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>
-rw-r--r-- | shell/hush.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c index 04dda0734..4a97293cc 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -10361,6 +10361,9 @@ int hush_main(int argc, char **argv) | |||
10361 | _exit(0); | 10361 | _exit(0); |
10362 | } | 10362 | } |
10363 | G.argv0_for_re_execing = argv[0]; | 10363 | G.argv0_for_re_execing = argv[0]; |
10364 | if (G.argv0_for_re_execing[0] == '-') | ||
10365 | /* reexeced hush should never be a login shell */ | ||
10366 | G.argv0_for_re_execing++; | ||
10364 | #endif | 10367 | #endif |
10365 | #if ENABLE_HUSH_TRAP | 10368 | #if ENABLE_HUSH_TRAP |
10366 | # if ENABLE_HUSH_FUNCTIONS | 10369 | # if ENABLE_HUSH_FUNCTIONS |