Bug in strftime %z (was: Possible defect in email.exe re: sent timestamp)

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Jan 7 21:50:00 GMT 2015


Hi Christian,


thanks for the testcase!

On Dec 19 19:44, Christian Franke wrote:
> Richard DeFuria wrote:
> >Hello,
> >
> >I noticed a defect in the latest cygwin email.exe tool.
> >
> >The defect is that the SENT timestamp is 1 hour off (i.e., one hour too
> >"old" compared to the current system time).
> >
> >My current email.exe version is as follows:
> >                 $ email -v
> >                 email - By Dean Jones; Version 3.2.0-git
> >
> >When I send an email using this tool (through my internal smtp server, which
> >is unchanged), the SENT timestamp is 1 hour old.
> >
> >When I send an email (via the same command line invocation) from an older
> >box using an older version of this tool, the SENT timestamp is correct.
> >
> >...
> >TZ is unchanged, but it set as follows on both systems:
> >                 $ echo $TZ
> >                 America/New_York
> >
> >Is there anything you recommend I check?
> >
> >This seems to have cropped up after my 12/15/2014 update of cygwin.
> 
> The email tool use strftime() to format the "Date" header line.
> 
> There is apparently a bug in the implementation of "%z" (offset from UTC)
> format in recent Cygwin strftime(). Affected are latest release and test
> versions of Cygwin:
> 
> Testcase:
> 
> $ uname -srvm
> CYGWIN_NT-6.1-WOW64 1.7.33-2(0.280/5/3) 2014-11-13 15:45 i686 Cygwin
> # (and also 1.7.34-003)
> 
> $ cat strftest.c
> #include <time.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(int argc, char **argv)
> {
>   time_t t = (argc > 1 ? atol(argv[1]) : time(NULL));
>   struct tm *tm = localtime(&t);
>   char buf[100];
>   strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z (%Z)", tm);
>   printf("%s\n", buf);
>   return 0;
> }
> 
> $ gcc -o strftest strftest.c
> 
> $ echo $TZ
> Europe/Berlin
> 
> $ ./strftest 1419010000
> 2014-12-19 18:26:40 +0200 (CET)
> 
> $ ./strftest 1436200000
> 2015-07-06 18:26:40 +0053 (CEST)

Surprisingly this is an old problem which exists in this form since 2011.
Weird that nobody noticed it so far.  Or I missed earlier bug reports :}
The underlying cause was that the info for std and dst offsets was taken
from the wrong spot in the file.  The weird 0053 offset is a result of
wrongly using the LMT offset for Europe/Berlin.

While this fixes the problem for recent timestamps, it will probably
fail for older timestamps when other dst rules were active.

The latest Cygwin versions come with an extended struct tm which adds
members tm_offset and tm_zone for newly built applications.  I'm working
on a patch so strftime utilizes these members if they are available.
I hope to get this finished tomorrow.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20150107/cf014834/attachment.sig>


More information about the Cygwin mailing list