git: ecb47941d089 - main - tzcode: Avoid integer truncation resulting in wrong weekday
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Nov 2026 23:49:49 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=ecb47941d089b9f9946afa6c52a33418491bfc66
commit ecb47941d089b9f9946afa6c52a33418491bfc66
Author: Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2026-11-25 21:39:41 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-11-26 23:48:25 +0000
tzcode: Avoid integer truncation resulting in wrong weekday
From a report[1] on the tz mailing list:
In timesub() the weekday is stored in (int) tm_wday before reduction
modulo seven (DAYSPERWEEK). Previously this could overflow a 32-bit
int, resulting in an incorrect weekday calculation.
Calculate two additional intermediate terms modulo seven to avoid an
intermediate value that does not fit in 32 bits.
We're committing this patch now so we can have something in place for
FreeBSD 15.2. If a different change is committed upstream we will
replace this.
[1] https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/O3RZGBKSO5GXBFDZKW2JXO3OQIIGYBF3/
PR: 300977
Requested by: re (cperciva)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D62073
---
contrib/tzcode/localtime.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c
index 397d7e8185c2..9bfbd332f81e 100644
--- a/contrib/tzcode/localtime.c
+++ b/contrib/tzcode/localtime.c
@@ -2419,8 +2419,8 @@ timesub(const time_t *timep, int_fast32_t offset,
+ ((y % DAYSPERWEEK - TM_YEAR_BASE % DAYSPERWEEK)
% DAYSPERWEEK
* (DAYSPERNYEAR % DAYSPERWEEK))
- + leaps_thru_end_of(y - 1)
- - leaps_thru_end_of(TM_YEAR_BASE - 1)
+ + leaps_thru_end_of(y - 1) % DAYSPERWEEK
+ - leaps_thru_end_of(TM_YEAR_BASE - 1) % DAYSPERWEEK
+ idays);
tmp->tm_wday %= DAYSPERWEEK;
if (tmp->tm_wday < 0)