From ef6b25b3bbfc1562d3a76bff85e6ffc4b53679ca Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 15 Mar 2017 17:04:23 +0800 Subject: [PATCH] Duplicate the command string --- su.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/su.c b/su.c index 828afa4b0..6847d3f33 100644 --- a/su.c +++ b/su.c @@ -585,7 +585,8 @@ static void fork_for_samsung(void) } } -static void concat_commands(char* command, int argc, char *argv[]) { +static char *concat_commands(int argc, char *argv[]) { + char command[ARG_MAX]; int i; command[0] = '\0'; for (i = optind - 1; i < argc; ++i) { @@ -594,6 +595,7 @@ static void concat_commands(char* command, int argc, char *argv[]) { else sprintf(command, "%s", argv[i]); } + return strdup(command); } int main(int argc, char *argv[]) { @@ -720,9 +722,7 @@ int su_main_nodaemon(int argc, char **argv) { switch(c) { case 'c': ctx.to.shell = DEFAULT_SHELL; - char command[ARG_MAX]; - concat_commands(command, argc, argv); - ctx.to.command = command; + ctx.to.command = concat_commands(argc, argv); optind = argc; break; case 'h':