public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info
@ 2011-11-11  0:08 pitrou at free dot fr
  2011-11-11 11:36 ` [Bug libc/13401] " rosslagerwall at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pitrou at free dot fr @ 2011-11-11  0:08 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13401

             Bug #: 13401
           Summary: calling localtime() or mktime() with a time far in the
                    past corrupts cached timezone info
           Product: glibc
           Version: 2.12
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: pitrou@free.fr
    Classification: Unclassified


See the following snippet:

#include <time.h>
#include <stdlib.h>

int main() {
    time_t t;
    struct tm tmp;
    char str[200];

    t = time(NULL);
    tmp = *gmtime(&t);
    tmp.tm_gmtoff = 0;
    tmp.tm_zone = NULL;

    strftime(str, sizeof(str), "%Z", &tmp);
    puts(str);

    t = -2461446500;
    localtime(&t);

    t = time(NULL);
    tmp = *gmtime(&t);
    tmp.tm_gmtoff = 0;
    tmp.tm_zone = NULL;

    strftime(str, sizeof(str), "%Z", &tmp);
    puts(str);

    return 0;
}


Output here is:
CET
PMT

After a bit of digging, it seems the external variable "tzname" gets (wrongly)
mutated by the localtime() call. The "%Z" format specifier just reuses that
info.

This issue got reproduced on several distributions, see
http://bugs.python.org/issue13309

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libc/13401] calling localtime() or mktime() with a time far in the past corrupts cached timezone info
  2011-11-11  0:08 [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info pitrou at free dot fr
@ 2011-11-11 11:36 ` rosslagerwall at gmail dot com
  2011-11-21 13:11 ` schwab@linux-m68k.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rosslagerwall at gmail dot com @ 2011-11-11 11:36 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13401

Ross Lagerwall <rosslagerwall at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rosslagerwall at gmail dot
                   |                            |com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libc/13401] calling localtime() or mktime() with a time far in the past corrupts cached timezone info
  2011-11-11  0:08 [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info pitrou at free dot fr
  2011-11-11 11:36 ` [Bug libc/13401] " rosslagerwall at gmail dot com
@ 2011-11-21 13:11 ` schwab@linux-m68k.org
  2011-11-21 15:02 ` pitrou at free dot fr
  2014-06-27 11:37 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: schwab@linux-m68k.org @ 2011-11-21 13:11 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13401

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2011-11-21 13:09:49 UTC ---
By overwriting tm_gmtoff and tm_zone the struct tm is no longer valid.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libc/13401] calling localtime() or mktime() with a time far in the past corrupts cached timezone info
  2011-11-11  0:08 [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info pitrou at free dot fr
  2011-11-11 11:36 ` [Bug libc/13401] " rosslagerwall at gmail dot com
  2011-11-21 13:11 ` schwab@linux-m68k.org
@ 2011-11-21 15:02 ` pitrou at free dot fr
  2014-06-27 11:37 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pitrou at free dot fr @ 2011-11-21 15:02 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13401

--- Comment #2 from Antoine Pitrou <pitrou at free dot fr> 2011-11-21 15:00:13 UTC ---
These fields are "overwritten" by hand in the example for ease of reproduction.
The actual use case is to fill the members of a struct tm by hand from user
data. Since tm_gmtoff and tm_zone are not specified by POSIX, they are left
alone, zero-filled (the struct is previously initialized with memset()).
There's no portable way that I know of to initialize these fields.

While the most basic use of strftime() indeed consists in formatting a struct
tm returned by a libc function (such as gmtime()), it seems reasonable to use
strftime() to format user-defined time data. Nowhere does POSIX seem to say
that the struct tm *has* to come from gmtime() or similar functions.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libc/13401] calling localtime() or mktime() with a time far in the past corrupts cached timezone info
  2011-11-11  0:08 [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info pitrou at free dot fr
                   ` (2 preceding siblings ...)
  2011-11-21 15:02 ` pitrou at free dot fr
@ 2014-06-27 11:37 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 11:37 UTC (permalink / raw)
  To: glibc-bugs

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

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-27 11:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-11  0:08 [Bug libc/13401] New: calling localtime() or mktime() with a time far in the past corrupts cached timezone info pitrou at free dot fr
2011-11-11 11:36 ` [Bug libc/13401] " rosslagerwall at gmail dot com
2011-11-21 13:11 ` schwab@linux-m68k.org
2011-11-21 15:02 ` pitrou at free dot fr
2014-06-27 11:37 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).