Bug 2821 - mktime() returns 2147483647 for various dates > 2038
Summary: mktime() returns 2147483647 for various dates > 2038
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.5
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-22 21:33 UTC by William Bardwell
Modified: 2014-07-04 16:35 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William Bardwell 2006-06-22 21:33:19 UTC
#include <stdio.h>
#include <time.h>
int main()
{
struct tm t2 = { 0, 0, 0, 1, 1, 2050 - 1900, 1, 1, 1};
time_t tt2 = mktime(&t2);
printf("%ld\n");
return 0;
}

That should print -1, but instead it prints 2147483647.
Sometime in 2063 mktime() starts returning -1 as it should.
Comment 1 Jakub Jelinek 2006-09-08 11:21:14 UTC
In this case diff of approx_biennia of repaired_t0 and approx_requested_biennia
is smaller than overflow_threshold (on 32-bit arches that's 21 biennia) and
so mktime_internal sets *offset to a very large value and continues rather than
returning -1 right away.  Not sure where the code should find that the current
timezone offset is not enough to undo the overflow.
Comment 2 Paul Eggert 2006-09-08 22:55:21 UTC
I've fixed this in gnulib mktime.c; you can find the patch in:

http://cvs.savannah.gnu.org/viewcvs/gnulib/lib/mktime.c?root=gnulib&r1=1.53&r2=1.54

Can you please port this patch back to glibc?  Thanks.
Comment 3 Ulrich Drepper 2006-09-09 16:56:38 UTC
I added the patch to cvs.