From 79e2598c48ad7e41d523f62368454c7d74f48268 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Nov 2016 22:13:08 +0100 Subject: 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 --- libbb/executable.c | 2 +- libbb/run_shell.c | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) (limited to 'libbb') 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) if (argv[0]) { BB_EXECVP_or_die(argv); } - run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); + run_shell(getenv("SHELL"), /*login:*/ 1, NULL); } 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) #endif /* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL. - * If COMMAND is nonzero, pass it to the shell with the -c option. - * If ADDITIONAL_ARGS is nonzero, pass it to the shell as more - * arguments. */ -void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) + * If ADDITIONAL_ARGS is not NULL, pass them to the shell. + */ +void FAST_FUNC run_shell(const char *shell, int loginshell, const char **additional_args) { const char **args; - int argno; - int additional_args_cnt = 0; - for (args = additional_args; args && *args; args++) - additional_args_cnt++; + args = additional_args; + while (args && *args) + args++; - args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); + args = xmalloc(sizeof(char*) * (2 + (args - additional_args))); if (!shell || !shell[0]) shell = DEFAULT_SHELL; @@ -70,16 +68,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, args[0] = bb_get_last_path_component_nostrip(shell); if (loginshell) args[0] = xasprintf("-%s", args[0]); - argno = 1; - if (command) { - args[argno++] = "-c"; - args[argno++] = command; - } + args[1] = NULL; if (additional_args) { - for (; *additional_args; ++additional_args) - args[argno++] = *additional_args; + int cnt = 1; + for (;;) + if ((args[cnt++] = *additional_args++) == NULL) + break; } - args[argno] = NULL; #if ENABLE_SELINUX if (current_sid) -- cgit v1.2.3-55-g6feb From 834aba3b72cb0e45153b95fed991522f7f1986c9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Nov 2016 14:13:58 +0100 Subject: comment and readme updates Signed-off-by: Denys Vlasenko --- libbb/common_bufsiz.c | 9 +++++++++ loginutils/README | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/common_bufsiz.c b/libbb/common_bufsiz.c index 1a3585169..2847eb57d 100644 --- a/libbb/common_bufsiz.c +++ b/libbb/common_bufsiz.c @@ -54,6 +54,15 @@ char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); #else # ifndef setup_common_bufsiz +/* For now, this is never used: + * scripts/generate_BUFSIZ.sh never generates "malloced" bufsiz1: + * enum { COMMON_BUFSIZE = 1024 }; + * extern char *const bb_common_bufsiz1; + * void setup_common_bufsiz(void); + * This has proved to be worse than the approach of defining + * larger bb_common_bufsiz1[] array. + */ + /* * It is not defined as a dummy macro. * It means we have to provide this function. diff --git a/loginutils/README b/loginutils/README index ce8851097..847b371b3 100644 --- a/loginutils/README +++ b/loginutils/README @@ -23,7 +23,7 @@ Getty should establish a new session and process group, and ensure that tty is a ctty. ??? Should getty ensure that other processes which might have opened -fds to this tty be dusconnected? agetty has a -R option which makes +fds to this tty be disconnected? agetty has a -R option which makes agetty call vhangup() after tty is opened. (Then agetty opens it again, since it probably vhangup'ed its own fd too). -- cgit v1.2.3-55-g6feb