From 85c6078659c6ff362941e217185377d52b3190c9 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 14 Jun 2012 16:17:15 -0400 Subject: [PATCH] Simplify "sudo -s" argv rewriting. --- src/parse_args.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/parse_args.c b/src/parse_args.c index bcdfd862f..1ee85a25b 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -378,17 +378,12 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp, * For shell mode we need to rewrite argv */ if (ISSET(mode, MODE_RUN) && ISSET(flags, MODE_SHELL)) { - char **av; - int ac; - - if (argc == 0) { - /* just the shell */ - ac = argc + 1; - av = emalloc2(ac + 1, sizeof(char *)); - memcpy(av + 1, argv, argc * sizeof(char *)); - } else { + char **av, *cmnd = NULL; + int ac = 1; + + if (argc != 0) { /* shell -c "command" */ - char *cmnd, *src, *dst; + char *src, *dst; size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) + strlen(argv[argc - 1]) + 1; @@ -406,12 +401,15 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp, dst--; /* replace last space with a NUL */ *dst = '\0'; - ac = 3; - av = emalloc2(ac + 1, sizeof(char *)); + ac += 2; /* -c cmnd */ + } + + av = emalloc2(ac + 1, sizeof(char *)); + av[0] = (char *)user_details.shell; /* plugin may override shell */ + if (cmnd != NULL) { av[1] = "-c"; av[2] = cmnd; } - av[0] = (char *)user_details.shell; /* plugin may override shell */ av[ac] = NULL; argv = av; -- 2.40.0