git: 0fe60dc65572 - main - fattime: fix fattime to timespec conversion of dates beyond 2106-02-06
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 01 May 2024 07:53:04 UTC
The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=0fe60dc65572f4d04992c97c0e262af5c50e7408 commit 0fe60dc65572f4d04992c97c0e262af5c50e7408 Author: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> AuthorDate: 2024-04-29 13:40:31 +0000 Commit: Toomas Soome <tsoome@FreeBSD.org> CommitDate: 2024-05-01 04:56:41 +0000 fattime: fix fattime to timespec conversion of dates beyond 2106-02-06 It turns out that the only conversion issue was in fattime2timespec, where multiplying the number of seconds in a day by the number of days overflowed 32-bit unsigned int for dates beyond 2106-02-07 06:28:15. Casting one of the multiplicands as time_t forces a 64-bit multiplication on systems where time_t is 64-bits and produces no binary changes on the one remaining system with 32-bit time_t (namely i386). Since the code is now tested & fixed, this change removes the fixme comments. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44755 --- sys/kern/subr_fattime.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/sys/kern/subr_fattime.c b/sys/kern/subr_fattime.c index 7b41b551eeef..569ee7f77112 100644 --- a/sys/kern/subr_fattime.c +++ b/sys/kern/subr_fattime.c @@ -63,11 +63,6 @@ * FAT timestamps have 7 bits for the year and starts at 1980, so * they can represent up to 2107 which means that the non-leap-year * 2100 must be handled. - * - * XXX: As long as time_t is 32 bits this is not relevant or easily - * XXX: testable. Revisit when time_t grows bigger. - * XXX: grepfodder: 64 bit time_t, y2100, y2.1k, 2100, leap year - * */ #include <sys/param.h> @@ -165,10 +160,7 @@ timespec2fattime(const struct timespec *tsp, int utc, uint16_t *ddp, } else { t2 -= T1980; - /* - * 2100 is not a leap year. - * XXX: a 32 bit time_t can not get us here. - */ + /* 2100 is not a leap year */ if (t2 >= ((2100 - 1980) / 4 * LYC + FEB)) t2++; @@ -242,17 +234,14 @@ fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, /* Month offset from leap-year cycle */ day += daytab[(dd >> 5) & 0x3f]; - /* - * 2100 is not a leap year. - * XXX: a 32 bit time_t can not get us here. - */ + /* 2100 is not a leap year */ if (day >= ((2100 - 1980) / 4 * LYC + FEB)) day--; /* Align with time_t epoch */ day += T1980; - tsp->tv_sec += DAY * day; + tsp->tv_sec += (time_t) DAY * day; if (!utc) tsp->tv_sec += utc_offset(); }