diff --git a/ChangeLog b/ChangeLog index 9343f91de3..a32ce789d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-10-01 Bruno Haible + + tzsanitize: Fix test failures on MSVC. + * lib/tzsanitize.c: Include . + (tzsanitize): Except on mingw, sanitize also the environment variable + in the process environment block. + 2026-10-01 Bruno Haible tzsanitize: New module. diff --git a/lib/tzsanitize.c b/lib/tzsanitize.c index 291bcd6170..dd4f31173f 100644 --- a/lib/tzsanitize.c +++ b/lib/tzsanitize.c @@ -25,6 +25,11 @@ #include #include +#if !defined __MINGW32__ +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include +#endif + void tzsanitize (void) { @@ -51,5 +56,28 @@ tzsanitize (void) if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=') ws[0] = L'$'; } +#if !defined __MINGW32__ + SetEnvironmentVariable ("TZ", NULL); +#endif } +#if !defined __MINGW32__ + /* On MSVC, we also need to sanitize the environment variables stored in the + process's environment block. + We don't lose much by assuming that the environment variable's value + is not too large. */ + else + { + /* Documentation: + */ + char tz_buf[256]; + DWORD tz_len = GetEnvironmentVariable ("TZ", tz_buf, sizeof (tz_buf)); + if (tz_len > 0 && tz_len < sizeof (tz_buf) + && strchr (tz_buf, '/') != NULL) + { + /* Documentation: + */ + SetEnvironmentVariable ("TZ", NULL); + } + } +#endif }