diff --git a/src/sudo.c b/src/sudo.c index 0ed053839..89d97b6e8 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -341,13 +341,48 @@ access_denied: return EXIT_FAILURE; } +/* + * Set the time zone using tzset(3), removing the user's TZ + * environment variable. The original value of TZ may still + * be present in the command's environment, depending on sudoers. + */ +static void +set_time_zone(void) +{ + /* Use system time zone, not user-specified. */ + unsetenv("TZ"); + (void) tzset(); +} + int os_init_common(int argc, char *argv[], char *envp[]) { + extern char **environ; + int envc; #ifdef STATIC_SUDOERS_PLUGIN preload_static_symbols(); #endif gc_init(); + + /* + * Make a copy of environ[] that is distinct from envp[]. + * This allows us to remove variables from sudo's environment + * while still providing the original envp to the plugins. + */ + for (envc = 0; envp[envc] != NULL; envc++) + continue; + if (envc != 0) { + char **new_env = reallocarray(NULL, sizeof(char *), envc + 1); + if (new_env == NULL || !gc_add(GC_PTR, new_env)) { + sudo_fatalx_nodebug(U_("%s: %s"), __func__, + U_("unable to allocate memory")); + } + for (envc = 0; envp[envc] != NULL; envc++) + new_env[envc] = envp[envc]; + new_env[envc] = NULL; + environ = new_env; + } + return 0; }