|
Message-ID: <20240325202329.GJ4163@brightrain.aerifal.cx> Date: Mon, 25 Mar 2024 16:23:29 -0400 From: Rich Felker <dalias@...c.org> To: Alexander Weps <exander77@...me> Cc: musl@...ts.openwall.com Subject: Re: Broken mktime calculations when crossing DST boundary On Mon, Mar 25, 2024 at 08:00:19PM +0000, Alexander Weps wrote: > On Monday, March 25th, 2024 at 20:38, Rich Felker <dalias@...c.org> wrote: > > > On Mon, Mar 25, 2024 at 06:57:49PM +0000, Alexander Weps wrote: > > > > > I am not sure which one you mean, all latest codes even includes > > > headers and main... > > > > > > https://www.openwall.com/lists/musl/2024/03/25/3 > > > > > I have no idea what to tell you. > > > > > > The first version I found that's actually compilable is: > > > > https://www.openwall.com/lists/musl/2024/03/25/11 > > > > It roughly behaves as expected on musl, except possibly not applying > > the tm_isdst=0, which is what was making the output confusing on > > glibc -- that threw the input back across the rule change cutoff. > > > > With tm_isdst=1 and tm_mday=31, on glibc, I get: > > > > before: 2011-12-31 00:00:00 WSDT 0 > > after1: 2011-12-31 00:00:00 WSDT 1325239200 > > after2: 2011-12-30 00:00:00 WSDT -1 > > after3: 2011-12-31 00:00:00 WSDT 1325239200 > > > > The -1 in the after2 line indicates that mktime failed with an error > > (and should not have modified tm; that's arguably a bug in glibc).The > > No, -1 means that was not able to make seconds since beginning of epoch. > It has nothing to do with modifying tm... That might actually be the correct interpretation. However, in that case glibc should not be returning -1, since the time is representable as time_t.. > Also, can you share the whole code, you did some changes and I don't > reproduce the result. Which sample it is based on? https://www.openwall.com/lists/musl/2024/03/25/11 The only change I made was tm_isdst=1 (you already had tm_mday=31 there). I'll attach the file anyway though. > I set tm_isdst=1 and tm_mday=31 in the example above and I get: > > $ gcc foo.c -o foo && TZ=Pacific/Apia ./foo > before: 2011-12-31 00:00:00 +13 0 > after1: 2012-01-01 01:00:00 +14 1325329200 > after2: 2011-12-31 01:00:00 +14 1325242800 > after3: 2012-01-01 01:00:00 +14 1325329200 That's close to what I'm seeing with tm_isdst=0: before: 2011-12-31 00:00:00 WSST 0 after1: 2012-01-01 01:00:00 WSDT 1325329200 after2: 2011-12-31 01:00:00 WSDT 1325242800 after3: 2012-01-01 01:00:00 WSDT 1325329200 With tm_isdst=1 I get: before: 2011-12-31 00:00:00 WSDT 0 after1: 2011-12-31 00:00:00 WSDT 1325239200 after2: 2011-12-30 00:00:00 WSDT -1 after3: 2011-12-31 00:00:00 WSDT 1325239200 This is on the very old glibc on a test system I had lying around, 2.28. It probably has different bugs (and seems unable to read the current zoneinfo file which is a newer version; thus the WSDT zone name from whatever old one it came with). > I do not get any -1 results. That's presumably because the bug that threw it into 2012 made it so there are no invalid dates appearing. > $ musl-gcc foo.c -o foo && TZ=Pacific/Apia ./foo > before: 2011-12-31 00:00:00 0 > after1: 2011-12-31 01:00:00 +14 1325242800 > after2: 2011-12-29 01:00:00 -10 1325156400 > after3: 2011-12-29 01:00:00 -10 1325156400 Are you sure you're not testing with tm_isdst=0? This is the output I get for tm_isdst=0 too. > > > partial modification that it made reflects the initial normalization > > (type 1 in my notation) but not the rule change normalization (type 2 > > in my notation) since glibc has failed the operation for an input date > > that does not exist on the calendar (it does not do type 2 > > normalization at all; it just rejects it). > > > > Running this same change on musl, I get: > > > > before: 2011-12-31 00:00:00 0 > > after1: 2011-12-31 00:00:00 +14 1325239200 > > after2: 2011-12-29 00:00:00 -10 1325152800 > > after3: 2011-12-29 00:00:00 -10 1325152800 > > > > which again is what I expect. From one side, the move-by-1-day changes > > the time to the next calendar day in that direction. From the other > > side, it's unable to change it. > > Glibc works without any issues as shown above on my machine. Both > forward and backward. No it doesn't. It jumped to completely the wrong day, 2012-01-01. In the case where it doesn't do that (tm_isdst=1), it emits a completely nonexistent date in the reverse direction: before: 2011-12-31 00:00:00 WSDT 0 after1: 2011-12-31 00:00:00 WSDT 1325239200 after2: 2011-12-30 00:00:00 WSDT -1 after3: 2011-12-31 00:00:00 WSDT 1325239200 This is because it *did* error out before finishing updating the tm fields. It performed normalization type 1, then said "nope!" and left the partial work behind. > Your results are off by one hour. And you start with WSDT (+14). > Without mktime. The initial date produced by glibc should be +13 as > Pacific/Apia is +13. I don't follow. It should never produce +13 in output, as non-DST is not active anywhere near this date. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.