From a38c2f99f81c2fc35c8ca209931c1c46e3e81023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sun, 2 Nov 2025 14:51:42 +0100 Subject: [PATCH] tzcode: Fix early tz change detection Assume tzdata is not fresh if last_checked is zero, as comparing the current time to last_checked less than __tz_change_interval after boot may produce a false negative. While here, invert the return value from tzdata_is_fresh() to better match its new name (it was previously called recheck_tzdata(), so zero for fresh and non-zero for stale made sense, but it doesn't now). PR: 269207 MFC after: 3 days Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53502 --- contrib/tzcode/localtime.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c index 1668475ea64..58099d234e2 100644 --- a/contrib/tzcode/localtime.c +++ b/contrib/tzcode/localtime.c @@ -1583,15 +1583,15 @@ tzdata_is_fresh(void) struct timespec now; if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) - return 0; - - if ((now.tv_sec - last_checked >= __tz_change_interval) || - (last_checked > now.tv_sec)) { - last_checked = now.tv_sec; return 1; + + if (last_checked == 0 || last_checked > now.tv_sec || + now.tv_sec - last_checked >= __tz_change_interval) { + last_checked = now.tv_sec; + return 0; } - return 0; + return 1; } #endif /* DETECT_TZ_CHANGES */ @@ -1642,7 +1642,7 @@ tzset_unlocked_name(char const *name) ? lcl_is_set < 0 : 0 < lcl_is_set && strcmp(lcl_TZname, name) == 0) #ifdef DETECT_TZ_CHANGES - if (tzdata_is_fresh() == 0) + if (tzdata_is_fresh()) #endif /* DETECT_TZ_CHANGES */ return; # ifdef ALL_STATE