jorton 2004/03/25 15:08:24
Modified: . CHANGES
test testtime.c
time/unix time.c
time/win32 time.c
Log:
* time/unix/time.c (apr_time_exp_get): Remove year check that failed for
2038, use apr_time_t to avoid overflow.
* time/win32/time.c (apr_time_exp_get): ditto
* test/testtime.c (test_2038): Add regression test.
Submitted by: Philip Martin <[EMAIL PROTECTED]>
Revision Changes Path
1.454 +3 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.453
retrieving revision 1.454
diff -w -d -u -r1.453 -r1.454
--- CHANGES 7 Mar 2004 21:15:04 -0000 1.453
+++ CHANGES 25 Mar 2004 23:08:23 -0000 1.454
@@ -117,6 +117,9 @@
Changes with APR 0.9.5
+ *) Fix apr_time_exp_get() for dates in 2038.
+ [Philip Martin <philip codematters.co.uk>]
+
*) Various build fixes: thread_rwlock.c on some Solaris platforms
(PR 22990); filestat.c on ReliantUnix (PR 22990); config.status
on IRIX (PR 19251). [Various]
1.52 +19 -0 apr/test/testtime.c
Index: testtime.c
===================================================================
RCS file: /home/cvs/apr/test/testtime.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -w -d -u -r1.51 -r1.52
--- testtime.c 13 Feb 2004 09:38:34 -0000 1.51
+++ testtime.c 25 Mar 2004 23:08:23 -0000 1.52
@@ -265,6 +265,24 @@
CuAssertTrue(tc, rv == APR_SUCCESS);
}
+/* 0.9.4 and earlier rejected valid dates in 2038 */
+static void test_2038(CuTest *tc)
+{
+ apr_time_exp_t xt;
+ apr_time_t t;
+
+ /* 2038-01-19T03:14:07.000000Z */
+ xt.tm_year = 138;
+ xt.tm_mon = 0;
+ xt.tm_mday = 19;
+ xt.tm_hour = 3;
+ xt.tm_min = 14;
+ xt.tm_sec = 7;
+
+ apr_assert_success(tc, "explode January 19th, 2038",
+ apr_time_exp_get(&t, &xt));
+}
+
CuSuite *testtime(void)
{
CuSuite *suite = CuSuiteNew("Time");
@@ -281,6 +299,7 @@
SUITE_ADD_TEST(suite, test_strftimesmall);
SUITE_ADD_TEST(suite, test_exp_tz);
SUITE_ADD_TEST(suite, test_strftimeoffset);
+ SUITE_ADD_TEST(suite, test_2038);
return suite;
}
1.76 +2 -7 apr/time/unix/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apr/time/unix/time.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -w -d -u -r1.75 -r1.76
--- time.c 13 Feb 2004 09:38:38 -0000 1.75
+++ time.c 25 Mar 2004 23:08:23 -0000 1.76
@@ -135,15 +135,10 @@
APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t, apr_time_exp_t *xt)
{
- int year;
- time_t days;
+ apr_time_t year = xt->tm_year;
+ apr_time_t days;
static const int dayoffset[12] =
{306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275};
-
- year = xt->tm_year;
- if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) {
- return APR_EBADDATE;
- }
/* shift new year to 1st March in order to make leap year calc easy */
1.49 +2 -8 apr/time/win32/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apr/time/win32/time.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -w -d -u -r1.48 -r1.49
--- time.c 13 Feb 2004 09:38:38 -0000 1.48
+++ time.c 25 Mar 2004 23:08:23 -0000 1.49
@@ -218,16 +218,10 @@
APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t,
apr_time_exp_t *xt)
{
- int year;
- time_t days;
+ apr_time_t year = xt->tm_year;
+ apr_time_t days;
static const int dayoffset[12] =
{306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275};
-
- year = xt->tm_year;
-
- if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) {
- return APR_EBADDATE;
- }
/* shift new year to 1st March in order to make leap year calc easy */