Bug 2209 - ctime(*t) can return garbage with large t
Summary: ctime(*t) can return garbage with large t
Status: RESOLVED FIXED
Alias: None
Product: uClibc
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 0.9.31
Hardware: PC Linux
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 07:04 UTC by David Ramos
Modified: 2010-07-28 07:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Patch containing testcase and proposed fix (1.58 KB, application/octet-stream)
2010-07-14 23:01 UTC, David Ramos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Ramos 2010-07-12 07:04:52 UTC
ctime() was updated in 0.9.31 to call localtime_r() instead of localtime() to avoid using a static buffer. Unfortunately, this change replaces the static buffer (which is zeroed out on initialization) with an uninitialized local buffer.

In the common case, this has no effect. However, with a sufficiently large time_t value, the value returned differs from that returned by asctime(localtime(t)), and thus violates the ANSI/ISO standard.

An example input is (on a 64-bit machine):
time_t t = 0x7ffffffffff6c600;

When passed to uClibc 0.9.30.3, the resulting string is:
"Sun Jan  0 15:32:16 1900"

When passed to uClibc 0.9.31, the resulting string is:
"??? ??? ?? 15:32:16 ????"

The recommended fix is to zero-out the 'tm' struct using memset() before calling localtime_r.
Comment 1 Bernhard Reutner-Fischer 2010-07-14 20:20:11 UTC
(In reply to comment #0)

> The recommended fix is to zero-out the 'tm' struct using memset() before
> calling localtime_r.

yes. Perhaps you could provide a testsuite entry for this one (test/time/tst-futimens1.c is a good example for a test)? That'd be awesome..
Comment 2 David Ramos 2010-07-14 23:01:23 UTC
Created attachment 2239 [details]
Patch containing testcase and proposed fix
Comment 3 Bernhard Reutner-Fischer 2010-07-28 07:36:56 UTC
Applied as 85b7ea33088fa16d319adbd228fc152f5b9da730. Thanks!