aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-03 22:13:08 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-03 22:13:08 +0100
commit79e2598c48ad7e41d523f62368454c7d74f48268 (patch)
treeb061ea33e433dcd509a99dc9726251f2e0f785e5 /libbb
parent2b288236e80938d29324072a823f46861bd07cd3 (diff)
downloadbusybox-w32-79e2598c48ad7e41d523f62368454c7d74f48268.tar.gz
busybox-w32-79e2598c48ad7e41d523f62368454c7d74f48268.tar.bz2
busybox-w32-79e2598c48ad7e41d523f62368454c7d74f48268.zip
su: expand help; simplify passing of -c CMD to run_shell()
Also, added a comment about bug 9401 (TIOCSTI input injection). function old new delta packed_usage 30909 30932 +23 su_main 470 487 +17 sulogin_main 260 258 -2 run_applet_and_exit 681 678 -3 run_shell 166 126 -40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/executable.c2
-rw-r--r--libbb/run_shell.c29
2 files changed, 13 insertions, 18 deletions
diff --git a/libbb/executable.c b/libbb/executable.c
index 05e70312f..3a1d4ff44 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -97,5 +97,5 @@ void FAST_FUNC exec_prog_or_SHELL(char **argv)
97 if (argv[0]) { 97 if (argv[0]) {
98 BB_EXECVP_or_die(argv); 98 BB_EXECVP_or_die(argv);
99 } 99 }
100 run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); 100 run_shell(getenv("SHELL"), /*login:*/ 1, NULL);
101} 101}
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index 4d92c3caa..b6b9360e8 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -50,19 +50,17 @@ void FAST_FUNC set_current_security_context(security_context_t sid)
50#endif 50#endif
51 51
52/* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL. 52/* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL.
53 * If COMMAND is nonzero, pass it to the shell with the -c option. 53 * If ADDITIONAL_ARGS is not NULL, pass them to the shell.
54 * If ADDITIONAL_ARGS is nonzero, pass it to the shell as more 54 */
55 * arguments. */ 55void FAST_FUNC run_shell(const char *shell, int loginshell, const char **additional_args)
56void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
57{ 56{
58 const char **args; 57 const char **args;
59 int argno;
60 int additional_args_cnt = 0;
61 58
62 for (args = additional_args; args && *args; args++) 59 args = additional_args;
63 additional_args_cnt++; 60 while (args && *args)
61 args++;
64 62
65 args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); 63 args = xmalloc(sizeof(char*) * (2 + (args - additional_args)));
66 64
67 if (!shell || !shell[0]) 65 if (!shell || !shell[0])
68 shell = DEFAULT_SHELL; 66 shell = DEFAULT_SHELL;
@@ -70,16 +68,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command,
70 args[0] = bb_get_last_path_component_nostrip(shell); 68 args[0] = bb_get_last_path_component_nostrip(shell);
71 if (loginshell) 69 if (loginshell)
72 args[0] = xasprintf("-%s", args[0]); 70 args[0] = xasprintf("-%s", args[0]);
73 argno = 1; 71 args[1] = NULL;
74 if (command) {
75 args[argno++] = "-c";
76 args[argno++] = command;
77 }
78 if (additional_args) { 72 if (additional_args) {
79 for (; *additional_args; ++additional_args) 73 int cnt = 1;
80 args[argno++] = *additional_args; 74 for (;;)
75 if ((args[cnt++] = *additional_args++) == NULL)
76 break;
81 } 77 }
82 args[argno] = NULL;
83 78
84#if ENABLE_SELINUX 79#if ENABLE_SELINUX
85 if (current_sid) 80 if (current_sid)