Skip to content

Commit db66916

Browse files
committed
sudo: ignore user-specified TZ environment variable
This avoids potential issues caused by a user-specified timezone when running sudo, such as the parsing of NOTBEFORE/NOTAFTER values in sudoers. The TZ variable is still passed to the command being run unless blocked by sudoers rules. Credit: - XlabAI Team of Tencent Xuanwu Lab ([email protected]) - Atuin Automated Vulnerability Discovery Engine - Guannan Wang, Zhanpeng Liu, Guancheng Li
1 parent e1fad8a commit db66916

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/sudo.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static void sudo_check_suid(const char *path);
9494
static char **get_user_info(struct user_details *);
9595
static void command_info_to_details(char * const info[],
9696
struct command_details *details);
97+
static void set_time_zone(void);
9798
static void gc_init(void);
9899

99100
/* Policy plugin convenience functions. */
@@ -158,7 +159,8 @@ main(int argc, char *argv[], char *envp[])
158159
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
159160
textdomain(PACKAGE_NAME);
160161

161-
(void) tzset();
162+
/* Use system time zone, not user-specified. */
163+
set_time_zone();
162164

163165
/* Must be done before we do any password lookups */
164166
#if defined(HAVE_GETPRPWNAM) && defined(HAVE_SET_AUTH_PARAMETERS)
@@ -336,6 +338,24 @@ main(int argc, char *argv[], char *envp[])
336338
return EXIT_FAILURE;
337339
}
338340

341+
/*
342+
* Set the time zone using tzset(3), ignoring the user's TZ
343+
* environment variable. The original value of TZ may still
344+
* be present in the command's environment, depending on sudoers.
345+
*/
346+
static void
347+
set_time_zone(void)
348+
{
349+
extern char **environ;
350+
char **real_environ = environ;
351+
char *empty[] = { NULL };
352+
353+
/* Use system time zone, not user-specified. */
354+
environ = empty;
355+
(void) tzset();
356+
environ = real_environ;
357+
}
358+
339359
int
340360
os_init_common(int argc, char *argv[], char *envp[])
341361
{

0 commit comments

Comments
 (0)