Bug 192016 - Incorrect result for %s in strftime
Summary: Incorrect result for %s in strftime
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-21 16:20 UTC by Daurnimator
Modified: 2018-10-13 22:09 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daurnimator 2014-07-21 16:20:12 UTC
The %s specifier in strftime doesn't respect timezones.

Example:

    #include <time.h>
    #include <stdio.h>

    int main() {
        time_t t = 1234567890;
        struct tm *tmp = gmtime(&t);
        char output[200];
        strftime(output, 200, "%s", tmp);
        printf("%s\n",output);
        return 0;
    }

Run with a non UTC timezone. e.g. TZ=GMT+9
Output will be 1234600290 instead of expected 1234567890

Location in BSD's libc: https://svnweb.freebsd.org/base/release/10.0.0/lib/libc/stdtime/strftime.c?view=markup#l312

This bug also exists in glibc: http://fossies.org/dox/glibc-2.19/strftime__l_8c_source.html#l01133
Bug filed at https://sourceware.org/bugzilla/show_bug.cgi?id=17189

It does not occur in musl: http://git.musl-libc.org/cgit/musl/tree/src/time/strftime.c?id=ac0acd569e01735fc6052d43fdf57f3a07c93f3d#n127
Comment 1 Yuri Pankov 2018-10-13 22:09:54 UTC
It's hard to say if it's a bug in FreeBSD libc and glibc or if it's a bug in musl as %s is NOT specified by POSIX.  See bug #30321 for more details.