Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 18 Jan 2018 16:25:07 +0000
From: Adrián López Tejedor <adrianlzt@...il.com>
To: musl@...ts.openwall.com
Subject: Differences between strftime in musl and glibc

Hi,

I was having a problem parsing dates with python in an Alpine container and
after some time digging I have found a difference in how musl and
glibc calculate the unix Epoch using strftime.

The format specifier to get the unix epoch is "%s", which is an extension
of GNU (
https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
).

In Glibc they use mktime (
https://github.com/bminor/glibc/blob/master/time/strftime_l.c#L1127), being
this function aware of time zone.

In musl is calculated without mktime, adding the seconds of each part of
the tm struct (
https://git.musl-libc.org/cgit/musl/tree/src/time/strftime.c?h=v1.1.18#n132)
and substracting the GMT offset. This method is unaware of the TZ data (I
have not seen how to define that gmt offset when using strptime).

Calling directly to musl/mktime work as expected.

I have attached a small program which shows the difference between musl and
glibc.

Compiled with glibc:
$ TZ=Europe/Madrid ./a.out
strftime: -3600
mktime: -3600
$ TZ=America/New_York ./a.out
strftime: 18000
mktime: 18000


Compiled with musl:
$ TZ=Europe/Madrid ./a.out
strftime: 0
mktime: -3600
$ TZ=America/New_York ./a.out
strftime: 0
mktime: 18000


Thanks!
Adrián

Content of type "text/html" skipped

View attachment "date_musl_glibc.c" of type "text/x-csrc" (498 bytes)

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.