Duplicate the command string

This commit is contained in:
topjohnwu 2017-03-15 17:04:23 +08:00
parent ff48996bbe
commit ef6b25b3bb

8
su.c
View File

@ -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; int i;
command[0] = '\0'; command[0] = '\0';
for (i = optind - 1; i < argc; ++i) { for (i = optind - 1; i < argc; ++i) {
@ -594,6 +595,7 @@ static void concat_commands(char* command, int argc, char *argv[]) {
else else
sprintf(command, "%s", argv[i]); sprintf(command, "%s", argv[i]);
} }
return strdup(command);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -720,9 +722,7 @@ int su_main_nodaemon(int argc, char **argv) {
switch(c) { switch(c) {
case 'c': case 'c':
ctx.to.shell = DEFAULT_SHELL; ctx.to.shell = DEFAULT_SHELL;
char command[ARG_MAX]; ctx.to.command = concat_commands(argc, argv);
concat_commands(command, argc, argv);
ctx.to.command = command;
optind = argc; optind = argc;
break; break;
case 'h': case 'h':