From d7c94707041c7956c2748d816d5f24fb6d272c44 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Sat, 13 Jun 2020 14:16:08 -0700 Subject: [PATCH] Backport the ksh2020 fix for timezone name determination This fix for `printf '%T' now` on FreeBSD was written by @krader1961. This is from https://github.com/att/ast/pull/591: On FreeBSD calling tzset() does not guarantee the tzname array will be correctly populated. On most systems that works but on FreeBSD you have to call localtime() or a related function (e.g., ctime()). This change also eliminates a potential, very small, memory leak due to the strdup()'ed tznames not being freed. src/lib/libast/tm/tminit.c: - Fix timezone name determination on FreeBSD and a memory leak. --- NEWS | 4 ++++ src/lib/libast/tm/tminit.c | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 6c1a2db32..6ae407ba9 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,10 @@ For full details, see the git log at: Any uppercase BUG_* names are modernish shell bug IDs. +2020-06-13: +- Fixed a timezone name determination bug on FreeBSD that caused the + output from `LC_ALL=C printf '%T' now` to print the wrong time zone name. + 2020-06-11: - Fixed a bug that caused running 'builtin -d' on a special builtin to diff --git a/src/lib/libast/tm/tminit.c b/src/lib/libast/tm/tminit.c index 191886195..c29e271a4 100644 --- a/src/lib/libast/tm/tminit.c +++ b/src/lib/libast/tm/tminit.c @@ -247,10 +247,6 @@ tmlocal(void) else if (e) environ[0] = e; } -#endif -#if _dat_tzname - local.standard = strdup(tzname[0]); - local.daylight = strdup(tzname[1]); #endif tmlocale(); @@ -296,10 +292,8 @@ tmlocal(void) * POSIX */ - if (!local.standard) - local.standard = strdup(tzname[0]); - if (!local.daylight) - local.daylight = strdup(tzname[1]); + local.standard = strdup(tzname[0]); + local.daylight = strdup(tzname[1]); } else #endif