From 827057b9f14684d260461676e370be371b1ed862 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 31 Jan 2017 02:51:22 +0800 Subject: [PATCH] Concat commands when using -c --- su.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/su.c b/su.c index e06bd9c09..0c72b3c93 100644 --- a/su.c +++ b/su.c @@ -586,6 +586,17 @@ static void fork_for_samsung(void) } } +static void concat_commands(char* command, int argc, char *argv[]) { + int i; + command[0] = '\0'; + for (i = optind - 1; i < argc; ++i) { + if (strlen(command)) + sprintf(command, "%s %s", command, argv[i]); + else + sprintf(command, "%s", argv[i]); + } +} + int main(int argc, char *argv[]) { if (argc == 2 && strcmp(argv[1], "--daemon") == 0) { //Everything we'll exec will be in su, not su_daemon @@ -709,7 +720,10 @@ int su_main_nodaemon(int argc, char **argv) { switch(c) { case 'c': ctx.to.shell = DEFAULT_SHELL; - ctx.to.command = optarg; + char command[ARG_MAX]; + concat_commands(command, argc, argv); + ctx.to.command = command; + optind = argc; break; case 'h': usage(EXIT_SUCCESS);