delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2017/05/05/14:54:14

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
Message-ID: <590CCAE9.3090904@gmx.de>
Date: Fri, 05 May 2017 20:56:41 +0200
From: "Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Bug in timestamp arithmetic
References: <6c031262-a53d-4ede-925d-ef279a2e1286 AT googlegroups DOT com>
In-Reply-To: <6c031262-a53d-4ede-925d-ef279a2e1286@googlegroups.com>
X-Provags-ID: V03:K0:CMzo3waXNKEu4CeJU0whRobynG/kQrO1Q50hhRMooE5ChvRnVqV
RxgD6q2fX3SJPIvf4z/iCTrqCHrb5MXew3Kgvy42WT5J1c2GfwoZlvIUwwyTXiDfdKGlTf2
OPNc1Ih4Zxj+voUbRCITtJ85qLFnoks6hcc27N66mZ6+jRPgVJBGRNm4gJwJJqoAZF3TL4C
mECcQ1G/6/ph/Br3HJYlw==
X-UI-Out-Filterresults: notjunk:1;V01:K0:S0IEIyhlKDw=:4/DDpLXa2pliJovOwKgB3j
Jzy1MxgMr9feq5i5u07uS8c0fIbgOyLu14bSlktAHeJOx5Okk41zWHheGY7fUSWE3L2Rb3Gnd
craAE0NDWiZXMfI4OF+BkYVUjc1vUHZbvdmUCCJPXLasBcY7tDO3Bs830eNo/pQ0M/uDeNOEH
oU2IpBwgKtbuvTj+d+xOPB4M5NEvulYNHBuRahsVdt9ZX+QDFMlN5A/LNHkWZXMR5dqz3iH0Q
PjL6ckrt6azkmCe3Mbz8OxZ/uydYgFLx3jmmFsRuRQ1I7PXkhM/r4SYfGGh7a0GYBcSWOLCZ0
EmejK2reqG1vl5Y2wlHgmPxx0j+sx+T4Rj592zO9o6vgMna9cWizHLTYVFpOKEB4XHk/ygU2P
YnTYwWW5v9MfB1KuhFYi0CSbP4de6SWaq9KwNXeTnNWzrk0CjYUZMhWlbPlU6ROUVEWzJa/pv
nh5EF6i83RQ1zH0/mTNfiZWne4s08Zi79RcuUiDOLKropmQCr459fiaOzWXU8DXMtYwDmgep/
AiPSmA0GKtXh5Nhadqib8YARhs01plb+xUUjcwv7alC03l58f+nZLDCnEwRJcPeLsraVMmi1v
1UcjSmWmQiYd1HypPa0WOkb3uNvXULbhGOBerxSFG2Qf3hbq8oP+SrwmjAWKF0IooonNjilIA
+3Y7Wrri8rdwoE66ZaOcEMzBm2ACbbP9/x0QOl1/sHPJY9I7/3VaVJeo+hpAV+aQhbWndcY4X
n7ZfRaMDbZJJEtrWez5xCrveySPDwX00zNMo9j9jkSRjm2KVrhzJkNzRXqx4+PyEC2jirMYAV
i3A/dFk
Reply-To: djgpp AT delorie DOT com

Am 05.05.2017 15:27, schrieb Arrigo Marchiori (ardovm AT yahoo DOT it) [via djgpp AT delorie DOT com]:
> Dear All,
>
> I am writing here to report a bug, as I could not do it through the delorie.com web site.
>
> On my system, I did not install any timezone files. libc therefore generates a ``default'' timezone. Such timezone has a random offset with respect to GMT.
>
> The effect is that ctime(0) returns random values, such as "31 December 1969", instead of "1 January 1970".
>
> This problem should be resolved by the patch you can find at the end of this message.
>
> The patch must be applied to src/libc/ansi/time/ctime.c
> Its effects are the following.
>
>   - In function tzload(): the default timezone created from _posixrules_data is actually parsed. It was not, because the nread variable was not updated with its size.
>
>   - In function tzparse(): the value for stdoffset is set to zero, if the parameter lastditch is set. Before this patch, the value of stdoffset was never assigned, and therefore the timezone received a random offset from GMT.
>
>   - In function tzparse(): after a new default timezone was created inside sp, the `defaulttype' field was not updated. If the default data from _posixrules was loaded correctly (see first point), sp->defaulttype would be set to 1. But previous types have just been overwritten, therefore this attribute must be set to zero, i.e. to the only current type.
>
> I hope this makes sense to you. Feel free to contact me if you need any more information on this, or if you think I can be of any help integrating it.
>
> Best regards,
>
>
> Arrigo
>
>
> --- src/libc/ansi/time/ctime.c.orig	2014-04-19 20:50:30.000000000 +0200
> +++ src/libc/ansi/time/ctime.c	2017-05-05 14:20:54.988023000 +0200
> @@ -362,7 +362,7 @@
>
>       /* We've got a built-in copy of posixrules just in case */
>       memcpy(buf, _posixrules_data, sizeof(_posixrules_data));
> -    i = sizeof(_posixrules_data);
> +    nread = sizeof(_posixrules_data);
>     }
>     else
>     {
> @@ -944,6 +944,7 @@
>       name += stdlen;
>       if (stdlen>= sizeof sp->chars)
>         stdlen = (sizeof sp->chars) - 1;
> +    stdoffset = 0;
>     }
>     else
>     {
> @@ -1156,6 +1157,7 @@
>       sp->ttis[0].tt_gmtoff = -stdoffset;
>       sp->ttis[0].tt_isdst = 0;
>       sp->ttis[0].tt_abbrind = 0;
> +    sp->defaulttype = 0;
>     }
>     sp->charcnt = stdlen + 1;
>     if (dstlen != 0)
>


I also have usually neither TZ set nor djtzn205 installed and can verify the
bug described by the poster.  An inspection of ctime.c from the repository
shows that the implementation has the different bugs described in the post
leading to random timestamp around 1969-12-24 for my installation.
IMO, the fix proposed is correct and it solves the problems as explained.
A library compiled from repository sources and with the proposed patch
applied produces the correct value for ctime(0) with and without djtzn205
installed.  Of course, if djtzn205 is installed, then ctime produces the
right time string so the patch does not break anything.
Any objections if the proposed fix is committed?

Regards,
Juan M. Guerrero

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019