main: fix the case where user has "halt" as login shell. Closes 9986
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 7 Jul 2017 17:08:56 +0000 (19:08 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 7 Jul 2017 17:08:56 +0000 (19:08 +0200)
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>
include/libbb.h
libbb/appletlib.c
libbb/vfork_daemon_rexec.c
shell/ash.c
shell/hush.c

index 1c9de3af0d9804c389459dd5d34db65a215171bf..0317c7d6ae662431b0e18a4ee9c16e0e694499a4 100644 (file)
@@ -1117,7 +1117,7 @@ int spawn_and_wait(char **argv) FAST_FUNC;
 int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
 #ifndef BUILD_INDIVIDUAL
 extern int find_applet_by_name(const char *name) FAST_FUNC;
-extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
+extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
 #endif
 
 /* Helpers for daemonization.
index 2dea2b43a0e64eca714c202d3dc08b83aa9c885c..df6584978f7d2132124cc3b4a25ddddbcf007d02 100644 (file)
@@ -877,13 +877,17 @@ static int busybox_main(char **argv)
 # endif
 
 # if NUM_APPLETS > 0
-void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
+void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
 {
        int argc = string_array_len(argv);
 
        /* Reinit some shared global data */
        xfunc_error_retval = EXIT_FAILURE;
-       applet_name = bb_get_last_path_component_nostrip(argv[0]);
+       /*
+        * We do not use argv[0]: do not want to repeat massaging of
+        * "-/sbin/halt" -> "halt", for example.
+        */
+       applet_name = name;
 
        /* Special case. POSIX says "test --help"
         * 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)
        {
                int applet = find_applet_by_name(name);
                if (applet >= 0)
-                       run_applet_no_and_exit(applet, argv);
+                       run_applet_no_and_exit(applet, name, argv);
        }
 #  endif
 
index 2695f99eee33e83ada3a2088b1ae728b548fe87c..576534ee5d5eca3698a93cfeeccb36527d3e5a27 100644 (file)
@@ -180,7 +180,7 @@ int FAST_FUNC spawn_and_wait(char **argv)
                         * as of yet (and that should probably always stay true).
                         */
                        /* xfunc_error_retval and applet_name are init by: */
-                       run_applet_no_and_exit(a, argv);
+                       run_applet_no_and_exit(a, argv[0], argv);
                }
 # endif
        }
index b7635a82332c3f108becf4a83b8f5dcb57dbaa54..8c2098dd9d745fd91ffce45435cf7fc1789166fc 100644 (file)
@@ -7717,7 +7717,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char *cmd, char **argv, char **
                        clearenv();
                        while (*envp)
                                putenv(*envp++);
-                       run_applet_no_and_exit(applet_no, argv);
+                       run_applet_no_and_exit(applet_no, cmd, argv);
                }
                /* re-exec ourselves with the new arguments */
                execve(bb_busybox_exec_path, argv, envp);
index 4ba6b3fdda38b1d465c67203d4fcce932c66f017..cf6d8cd9feab0062b22062641c1d4caa465578cb 100644 (file)
@@ -7063,7 +7063,7 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
                                /* Do not leak open fds from opened script files etc */
                                close_all_FILE_list();
                                debug_printf_exec("running applet '%s'\n", argv[0]);
-                               run_applet_no_and_exit(a, argv);
+                               run_applet_no_and_exit(a, argv[0], argv);
                        }
 # endif
                        /* Re-exec ourselves */