From: Todd C. Miller Date: Thu, 10 Nov 2016 17:11:18 +0000 (-0700) Subject: Add the argument vector allocated for -s and -i mode to the garbage X-Git-Tag: SUDO_1_8_19^2~52 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efe957544fecc63094575775433f902d230ca2dd;p=sudo Add the argument vector allocated for -s and -i mode to the garbage collector list. Avoids an ASAN warning on exit when the -s or -i flags are used. --- diff --git a/src/parse_args.c b/src/parse_args.c index 28372f5bb..22efddd72 100644 --- a/src/parse_args.c +++ b/src/parse_args.c @@ -464,6 +464,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, cmnd = dst = reallocarray(NULL, cmnd_size, 2); if (cmnd == NULL) sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + if (!gc_add(GC_PTR, cmnd)) + exit(1); + for (av = argv; *av != NULL; av++) { for (src = *av; *src != '\0'; src++) { /* quote potential meta characters */ @@ -483,6 +486,9 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, av = reallocarray(NULL, ac + 1, sizeof(char *)); if (av == NULL) sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + if (!gc_add(GC_PTR, av)) + exit(1); + av[0] = (char *)user_details.shell; /* plugin may override shell */ if (cmnd != NULL) { av[1] = "-c"; diff --git a/src/sudo.c b/src/sudo.c index a56751d38..9a98785c5 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -89,11 +89,7 @@ static int sudo_mode; struct sudo_gc_entry { SLIST_ENTRY(sudo_gc_entry) entries; - enum sudo_gc_types { - GC_UNKNOWN, - GC_VECTOR, - GC_PTR - } type; + enum sudo_gc_types type; union { char **vec; void *ptr; @@ -113,7 +109,6 @@ static void sudo_check_suid(const char *path); static char **get_user_info(struct user_details *); static void command_info_to_details(char * const info[], struct command_details *details); -static bool gc_add(enum sudo_gc_types type, void *ptr); static void gc_init(void); /* Policy plugin convenience functions. */ @@ -1509,7 +1504,7 @@ iolog_unlink(struct plugin_container *plugin) debug_return; } -static bool +bool gc_add(enum sudo_gc_types type, void *v) { #ifdef NO_LEAKS diff --git a/src/sudo.h b/src/sudo.h index e871acde4..3ac2c9db4 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -180,7 +180,12 @@ struct command_status { int val; }; -struct timeval; +/* Garbage collector data types. */ +enum sudo_gc_types { + GC_UNKNOWN, + GC_VECTOR, + GC_PTR +}; /* For fatal() and fatalx() (XXX - needed?) */ void cleanup(int); @@ -206,6 +211,7 @@ bool exec_setup(struct command_details *details, const char *ptyname, int ptyfd) int policy_init_session(struct command_details *details); int run_command(struct command_details *details); int os_init_common(int argc, char *argv[], char *envp[]); +bool gc_add(enum sudo_gc_types type, void *v); extern const char *list_user; extern struct user_details user_details; extern int sudo_debug_instance;