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

Christian Franke Christian.Franke@t-online.de
Fri Dec 19 18:44:00 GMT 2014


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)


GNU date(1) uses its own implementation and works as expected:

$ date '+%Y-%m-%d %H:%M:%S %z (%Z)' -d @1419010000
2014-12-19 18:26:40 +0100 (CET)

$ date '+%Y-%m-%d %H:%M:%S %z (%Z)' -d @1436200000
2015-07-06 18:26:40 +0200 (CEST)


Possible workaround: Avoid timezone names, used timezone spec instead:

$ export TZ=CET-1CEST,M3.5.0/2,M10.5.0/2

$ ./strftest 1419010000
2014-12-19 18:26:40 +0100 (CET)

$ ./strftest 1436200000
2015-07-06 18:26:40 +0200 (CEST)


Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list