diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-07 19:08:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-18 19:20:58 +0200 |
commit | 54916641be96b6b13e3df9b09dd5a78abefb612b (patch) | |
tree | 72b69b752000bb262f97669f6d7b91b770b8f38b | |
parent | 80cb8796f86754faa1569994b9355eeffe0b7759 (diff) | |
download | busybox-w32-54916641be96b6b13e3df9b09dd5a78abefb612b.tar.gz busybox-w32-54916641be96b6b13e3df9b09dd5a78abefb612b.tar.bz2 busybox-w32-54916641be96b6b13e3df9b09dd5a78abefb612b.zip |
main: fix the case where user has "halt" as login shell. Closes 9986
halt::0:0::/:/sbin/halt
function old new delta
run_applet_and_exit 748 751 +3
run_applet_no_and_exit 467 459 -8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/appletlib.c | 10 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | shell/hush.c | 2 |
5 files changed, 11 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h index 557978e66..8eccd8170 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1108,7 +1108,7 @@ int spawn_and_wait(char **argv) FAST_FUNC; | |||
1108 | int run_nofork_applet(int applet_no, char **argv) FAST_FUNC; | 1108 | int run_nofork_applet(int applet_no, char **argv) FAST_FUNC; |
1109 | #ifndef BUILD_INDIVIDUAL | 1109 | #ifndef BUILD_INDIVIDUAL |
1110 | extern int find_applet_by_name(const char *name) FAST_FUNC; | 1110 | extern int find_applet_by_name(const char *name) FAST_FUNC; |
1111 | extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; | 1111 | extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; |
1112 | #endif | 1112 | #endif |
1113 | 1113 | ||
1114 | /* Helpers for daemonization. | 1114 | /* Helpers for daemonization. |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 2dea2b43a..df6584978 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -877,13 +877,17 @@ static int busybox_main(char **argv) | |||
877 | # endif | 877 | # endif |
878 | 878 | ||
879 | # if NUM_APPLETS > 0 | 879 | # if NUM_APPLETS > 0 |
880 | void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | 880 | void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) |
881 | { | 881 | { |
882 | int argc = string_array_len(argv); | 882 | int argc = string_array_len(argv); |
883 | 883 | ||
884 | /* Reinit some shared global data */ | 884 | /* Reinit some shared global data */ |
885 | xfunc_error_retval = EXIT_FAILURE; | 885 | xfunc_error_retval = EXIT_FAILURE; |
886 | applet_name = bb_get_last_path_component_nostrip(argv[0]); | 886 | /* |
887 | * We do not use argv[0]: do not want to repeat massaging of | ||
888 | * "-/sbin/halt" -> "halt", for example. | ||
889 | */ | ||
890 | applet_name = name; | ||
887 | 891 | ||
888 | /* Special case. POSIX says "test --help" | 892 | /* Special case. POSIX says "test --help" |
889 | * should be no different from e.g. "test --foo". | 893 | * should be no different from e.g. "test --foo". |
@@ -927,7 +931,7 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv) | |||
927 | { | 931 | { |
928 | int applet = find_applet_by_name(name); | 932 | int applet = find_applet_by_name(name); |
929 | if (applet >= 0) | 933 | if (applet >= 0) |
930 | run_applet_no_and_exit(applet, argv); | 934 | run_applet_no_and_exit(applet, name, argv); |
931 | } | 935 | } |
932 | # endif | 936 | # endif |
933 | 937 | ||
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 2695f99ee..576534ee5 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -180,7 +180,7 @@ int FAST_FUNC spawn_and_wait(char **argv) | |||
180 | * as of yet (and that should probably always stay true). | 180 | * as of yet (and that should probably always stay true). |
181 | */ | 181 | */ |
182 | /* xfunc_error_retval and applet_name are init by: */ | 182 | /* xfunc_error_retval and applet_name are init by: */ |
183 | run_applet_no_and_exit(a, argv); | 183 | run_applet_no_and_exit(a, argv[0], argv); |
184 | } | 184 | } |
185 | # endif | 185 | # endif |
186 | } | 186 | } |
diff --git a/shell/ash.c b/shell/ash.c index 6d46e3719..2e1d1e7b7 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -7688,7 +7688,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char ** | |||
7688 | clearenv(); | 7688 | clearenv(); |
7689 | while (*envp) | 7689 | while (*envp) |
7690 | putenv(*envp++); | 7690 | putenv(*envp++); |
7691 | run_applet_no_and_exit(applet_no, argv); | 7691 | run_applet_no_and_exit(applet_no, cmd, argv); |
7692 | } | 7692 | } |
7693 | /* re-exec ourselves with the new arguments */ | 7693 | /* re-exec ourselves with the new arguments */ |
7694 | execve(bb_busybox_exec_path, argv, envp); | 7694 | execve(bb_busybox_exec_path, argv, envp); |
diff --git a/shell/hush.c b/shell/hush.c index db8ca4f97..7cceab30d 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -7064,7 +7064,7 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
7064 | /* Do not leak open fds from opened script files etc */ | 7064 | /* Do not leak open fds from opened script files etc */ |
7065 | close_all_FILE_list(); | 7065 | close_all_FILE_list(); |
7066 | debug_printf_exec("running applet '%s'\n", argv[0]); | 7066 | debug_printf_exec("running applet '%s'\n", argv[0]); |
7067 | run_applet_no_and_exit(a, argv); | 7067 | run_applet_no_and_exit(a, argv[0], argv); |
7068 | } | 7068 | } |
7069 | # endif | 7069 | # endif |
7070 | /* Re-exec ourselves */ | 7070 | /* Re-exec ourselves */ |