From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 6407F2126E for ; Mon, 25 Mar 2024 21:23:26 +0100 (CET) Received: (qmail 19499 invoked by uid 550); 25 Mar 2024 20:18:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 18425 invoked from network); 25 Mar 2024 20:18:38 -0000 Date: Mon, 25 Mar 2024 16:23:29 -0400 From: Rich Felker To: Alexander Weps Cc: musl@lists.openwall.com Message-ID: <20240325202329.GJ4163@brightrain.aerifal.cx> References: <20240324192258.GY4163@brightrain.aerifal.cx> <20240325131318.GD4163@brightrain.aerifal.cx> <20240325134252.GE4163@brightrain.aerifal.cx> <20240325180208.GF4163@brightrain.aerifal.cx> <20240325185339.GG4163@brightrain.aerifal.cx> <4-8Ne4x6ZXfJmyaJ2YBFpLfCYySv9--JLQJl9OcSwaKyCashDhJXsqAPuh7G8QYwQpn2JnjUJxfZX8t9Fo101Mg_6rwb_MpmbRhFRUpYoz8=@pm.me> <20240325193813.GH4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] 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 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