Author: mturk
Date: Sat Aug 29 16:43:21 2009
New Revision: 809156
URL: http://svn.apache.org/viewvc?rev=809156&view=rev
Log:
Guard against invalid times
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c
commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c?rev=809156&r1=809155&r2=809156&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c Sat Aug 29
16:43:21 2009
@@ -90,6 +90,7 @@
#else
tm = *gmtime(&tt);
#endif
+ printf("Year is %d\n", tm.tm_year);
if (tm.tm_year >= 1900)
tm.tm_year -= 1900;
if (tm.tm_year < 80) {
@@ -100,6 +101,12 @@
}
else
tm.tm_year -= 80;
+ if (tm.tm_year > 207) {
+ /* December 31st 2107 is the
+ * maximum date DOS format can handle.
+ */
+ return 0xFF9F0000;
+ }
rv = ((acr_uint32_t)(tm.tm_year) << 25) |
((acr_uint32_t)(tm.tm_mon + 1) << 21) |
((acr_uint32_t)(tm.tm_mday) << 16) |
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c?rev=809156&r1=809155&r2=809156&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/time.c Sat Aug 29
16:43:21 2009
@@ -63,8 +63,9 @@
if (FileTimeToDosDateTime(&ft, &dd, &dt))
return ((acr_uint32_t)dd << 16) | (acr_uint32_t)dt;
else {
- /* January 1st 1980.
- */
- return 0x00210000;
+ if (t > ACR_INT64_C(4354732800000000))
+ return 0xFF9F0000;
+ else
+ return 0x00210000;
}
}
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=809156&r1=809155&r2=809156&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Sat Aug 29
16:43:21 2009
@@ -411,8 +411,9 @@
* Which happens to be when I wrote the new tests.
*/
static acr_time_t test_2002 = ACR_INT64_C(1032030336186711);
-static acr_time_t test_1980 = ACR_INT64_C(315532800000000);
-static acr_time_t test_2107 = ACR_INT64_C(4403030400000000);
+static acr_time_t test_2107 = ACR_INT64_C(4354732800000000); /* Max Dos date */
+static acr_time_t test_1980 = ACR_INT64_C(315532800000000); /* Min Dos date */
+
static int test_times(int argc, const char *const argv[])
{
int failed = 0;