From ca8c71a20870a79a55022df5c04b8f13a56748b2 Mon Sep 17 00:00:00 2001 From: Mike Gilbert Date: Wed, 17 Apr 2024 13:59:58 -0400 Subject: [PATCH] winpr: improve timezone detection when TZ is set The TZ variable may either contain a direct timezone representation, or a reference to a file in tzfile(5) format. Mapping a direct timezone representation to a Windows timezone would be difficult. According to tzset(3), a file reference should start with a colon, though glibc treats it as optional. It may be an absolute path or a path relative to /usr/share/zoneinfo. Adjust winpr_detect_windows_time_zone to accept either. --- winpr/libwinpr/timezone/timezone.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 6ca3e5443..c9aec7523 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -308,6 +308,11 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void) free(tzid); tzid = NULL; } + else if (tzid[0] == ':') + { + /* Remove leading colon, see tzset(3) */ + memmove(tzid, tzid + 1, nSize - sizeof(char)); + } } if (tzid == NULL) @@ -323,7 +328,14 @@ static TIME_ZONE_ENTRY* winpr_detect_windows_time_zone(void) char buf[1024] = { 0 }; const char* links[] = { buf }; - snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid); + if (tzid[0] == '/') + { + /* Full path given in TZ */ + links[0] = tzid; + } + else + snprintf(buf, ARRAYSIZE(buf), "%s%s", zipath, tzid); + ntzid = winpr_get_timezone_from_link(links, 1); if (ntzid != NULL) {