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=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE 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 584E72153C for ; Sat, 23 Mar 2024 19:57:39 +0100 (CET) Received: (qmail 29888 invoked by uid 550); 23 Mar 2024 18:52:57 -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 29855 invoked from network); 23 Mar 2024 18:52:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1711220245; x=1711479445; bh=qqCNjRCtj+LcRDmGjvOerCppiDXukVnMusrL0+Ntabk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Q9sul4HvBGkyjfba+iHSZoh8910kDThYGzPWFFJ/Spoj1mD3XKijxJcIKom/Yucna WrMSrfhQZHE9VRps0GCAo1BujI0LIYV6onlJ2LTZDH7CaSmer2SlLWlCJ5PR459LgR l5c8CO0XMhdXZd8djy2s/IYjwK03JtEcOVomJ3eXfrWsoM1G1oJ3XkbxczfU81a11k kyxzeuAKgDkLcF8EOgPb4dio8v4LmQyfIfB4Mqhhj5XgE52QBjdn2i3Qgc49OjIcVd OzcPm2J64HjJcECtpSs2fZ2ubRMGs5rOLe0eseqhIBYvCtdXL4CIYTitwHnD86f/nD 4pDIRLLJu4TuA== Date: Sat, 23 Mar 2024 18:57:21 +0000 To: musl@lists.openwall.com From: Alexander Weps Cc: Markus Wichmann Message-ID: In-Reply-To: <-44SZR0LbVoyD5lp_9VrAFnIjGNbDvibCVUYEprqMToPidjopTHM4aLZuhjomrGJtvpGrc_gjrgK6roKWwunjEkk1y-BKRhtlGpWjnslQNA=@pm.me> References: <528SeRFaPfDw7fA4kqKDlio1U4RB_t9nmUemPcWw9_t1e2hBDpXYFmOqxAC37szgYvAVtmTuXWsmT64SSN3cSQFVdrQqXUAgkdTMPZQ0bg0=@pm.me> <20240323123148.GR4163@brightrain.aerifal.cx> <5zS95V9QjlCRMv6JvbMFzFIOvxQTigAsEvu0YNSYzcu1ZHdki6sue6yqDXeWlRcSe_jhCQxHdHc0fvKu-3H7lCvyAeYgQTsK7KWMepbly3Y=@pm.me> <20240323153146.GS4163@brightrain.aerifal.cx> <-44SZR0LbVoyD5lp_9VrAFnIjGNbDvibCVUYEprqMToPidjopTHM4aLZuhjomrGJtvpGrc_gjrgK6roKWwunjEkk1y-BKRhtlGpWjnslQNA=@pm.me> Feedback-ID: 20507743:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] Broken mktime calculations when crossing DST boundary So, in the meantime, I was debugging with not setting tm_isdst =3D -1; This causes pretty annoying behavior: before: 2010-10-31 14:00:00 tm_sec: 0 tm_min: 0 tm_hour: 14 tm_mday: 31 tm_mon: 9 tm_year: 110 tm_wday: 0 tm_yday: 0 tm_isdst: 0 tm_gmtoff: 3600 tm_zone: CET tm->tm_hour =3D 0; <-- reset hour field mktime(&tm); after: 2010-10-31 01:00:00 CEST <-- 10:00:00 instead of 00:00:00 tm_sec: 0 tm_min: 0 tm_hour: 1 tm_mday: 31 tm_mon: 9 tm_year: 110 tm_wday: 0 tm_yday: 303 tm_isdst: 1 tm_gmtoff: 7200 tm_zone: CEST tm->tm_hour =3D 0; mktime(&tm); after: 2010-10-31 00:00:00 CEST <-- second run gives a correct value tm_sec: 0 tm_min: 0 tm_hour: 0 tm_mday: 31 tm_mon: 9 tm_year: 110 tm_wday: 0 tm_yday: 303 tm_isdst: 1 tm_gmtoff: 7200 tm_zone: CEST This basically means that setting field twice produces different value each= time: AW On Saturday, March 23rd, 2024 at 17:54, Alexander Weps wr= ote: > One of the main purposes of struct tm is to calculate date and time, by a= dding and substracting it's fields. > > > mktime cannot tell whether your non-normalized input was the result of > > you starting with 01:00:02 and adding 1 hour (in which case, our > > output does not reflect your intent) or of you starting with 3:00:02 > > and subtracting 1 hour (in which case, our output does reflect your > > intent). > > > We are not adding hours here, your example is completely unrelated. > > We are adding or subtracting minutes that changes hours. > > tm_sec: 2 > tm_min: 60 > tm_hour: 1 > > vs > > tm_sec: 2 > tm_min: 0 > tm_hour: 2 > > And: > > tm_sec: 2 > tm_min: 59 > tm_hour: 1 > > vs > > tm_sec: 2 > tm_min: -1 > tm_hour: 2 > > AW > > > > > On Saturday, March 23rd, 2024 at 16:31, Rich Felker dalias@libc.org wrote= : > > > On Sat, Mar 23, 2024 at 01:49:48PM +0000, Alexander Weps wrote: > > > > > I don't think time can go backwards by incrementing field under any c= onditions. > > > > > > Going from: > > > tm_sec: 2 > > > tm_min: 60 > > > tm_hour: 1 > > > tm_mday: 31 > > > tm_mon: 2 > > > tm_year: 124 > > > tm_wday: 0 > > > tm_yday: 90 > > > tm_isdst: -1 > > > > > > To: > > tm_sec: 1 > tm_min: 59 > tm_hour: 2 > > > > tm_sec: 2 > > > tm_min: 0 > > > tm_hour: 1 > > > tm_mday: 31 > > > tm_mon: 2 > > > tm_year: 124 > > > tm_wday: 0 > > > tm_yday: 90 > > > tm_isdst: 0 > > > > > > Seems to be plain wrong. I cannot come up with any argument for this > > > being correct under any conditions. > > > > The above broke-down time is 2:00:02, which does not exist on that day > > as a normalized time. If interpreted as non-DST, it would be just a > > couple seconds past the end of non-DST (1:59:59.99999..). If > > interpreted as DST, it would be just under an hour before the start of > > DST (3:00:00), which, after normalization, is 1:00:02 non-DST. > > > > mktime cannot tell whether your non-normalized input was the result of > > you starting with 01:00:02 and adding 1 hour (in which case, our > > output does not reflect your intent) or of you starting with 3:00:02 > > and subtracting 1 hour (in which case, our output does reflect your > > intent). > > > > > mktime was given a struct tm with uncertain STD/DST, it deduced it > > > is STD and then thrown away 60 minute information. The minutes got > > > reset from 60 to 0 and no other change was done. > > > > It did not deduce it was STD. It deduced it was non-normalized DST > > rather than non-normalized STD (this is an arbitrary choice), then > > normalized it and got STD. > > > > Rich