This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/17646] New: mktime: unpredictable return value for ambiguous time, depends on previous mktime call


https://sourceware.org/bugzilla/show_bug.cgi?id=17646

            Bug ID: 17646
           Summary: mktime: unpredictable return value for ambiguous time,
                    depends on previous mktime call
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: michael.haubenwallner@ssi-schaefer.com
                CC: drepper.fsp at gmail dot com

Created attachment 7971
  --> https://sourceware.org/bugzilla/attachment.cgi?id=7971&action=edit
ambiguous-mktime.c

Passing struct tm values with tm_isdst=-1 to mktime() from within the
"ambiguous" time range (during the DST backwards-transition), the resulting
time_t value depends on the result of the previous call to mktime().

While the behavior is undefined, it still should be predictable/consistent in
that it either does:
* detect the ambiguous timestamp's DST value to be the same as the current
  timestamp's dst value (seen on AIX), or
* detect the ambiguous timestamp's DST value to always be non-DST
  (seen on HP-UX, Solaris, Windows), or
* detect the ambiguous timestamp's DST value to always be DST
  (not seen anywhere yet).

Compile and run attached test program:
  $ gcc ambiguous-test.c -o ambiguous-test
  $ TZ=Europe/Vienna ./ambiguous-test
2014-10-26 00:37:00 = 1414276620 (1, 7200, CEST)
2014-10-26 01:37:00 = 1414280220 (1, 7200, CEST)
2014-10-26 02:37:00 = 1414283820 (1, 7200, CEST) # first
2014-10-26 03:37:00 = 1414291020 (0, 3600, CET )
2014-10-26 04:37:00 = 1414294620 (0, 3600, CET )
2014-10-26 03:37:00 = 1414291020 (0, 3600, CET )
2014-10-26 02:37:00 = 1414287420 (0, 3600, CET ) # inconsistent with first
2014-10-26 01:37:00 = 1414280220 (1, 7200, CEST)
2014-10-26 00:37:00 = 1414276620 (1, 7200, CEST)
FAILED (inconsistent)

Application developers don't have control over previous mktime() calls, but the
current one only.

However, I'm wondering how this could have gone unnoticed for almost 20 years,
as this IMHO was introduced in 1995 with 'static time_t localtime_offset' in
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=80fd73873bd51e58039983a9416ef3bb97bdac57

Thanks!
/haubi/

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]