You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/29 18:29:04 UTC
svn commit: r809154 - in /commons/sandbox/runtime/trunk/src/main/native/os:
unix/time.c win32/time.c
Author: mturk
Date: Sat Aug 29 16:29:03 2009
New Revision: 809154
URL: http://svn.apache.org/viewvc?rev=809154&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
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=809154&r1=809153&r2=809154&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:29:03 2009
@@ -59,7 +59,8 @@
ACR_DECLARE(acr_time_t) ACR_Dos2AcrTime(acr_uint32_t t)
{
- struct tm tm;
+ struct tm tm;
+ acr_time_t rv;
tm.tm_year = ((t & 0xFE000000) >> 25) + 80;
tm.tm_mon = ((t & 0x01E00000) >> 21) - 1;
@@ -68,24 +69,33 @@
tm.tm_min = ((t & 0x000007E0) >> 5);
tm.tm_sec = ((t & 0x0000001F) << 1);
- return tm2time(&tm);
+ rv = tm2time(&tm);
+ if (rv < ACR_INT64_C(315532800000000)) {
+ /* January 1st 1980 as unix time in microseconds */
+ rv = ACR_INT64_C(315532800000000);
+ }
+ return rv;
}
ACR_DECLARE(acr_uint32_t) ACR_Acr2DosTime(acr_time_t t)
{
struct tm tm;
acr_uint32_t rv;
- time_t tt = (time_t)ACR_ALIGN((t / ACR_USEC_PER_SEC), 2);
+ time_t tt;
+ /* Round up to two seconds */
+ tt = (time_t)ACR_ALIGN((t / ACR_USEC_PER_SEC), 2);
#if 1
gmtime_r(&tt, &tm);
#else
tm = *gmtime(&tt);
#endif
- if (tm.tm_year > 1900)
+ if (tm.tm_year >= 1900)
tm.tm_year -= 1900;
if (tm.tm_year < 80) {
- /* January 1st 1980 */
+ /* January 1st 1980 is the
+ * minimum data DOS format can handle.
+ */
return 0x00210000;
}
else
@@ -94,7 +104,7 @@
((acr_uint32_t)(tm.tm_mon + 1) << 21) |
((acr_uint32_t)(tm.tm_mday) << 16) |
((acr_uint32_t)(tm.tm_hour) << 11) |
- ((acr_uint32_t)(tm.tm_min) << 5) |
- ((acr_uint32_t)(tm.tm_sec) >> 1);
+ ((acr_uint32_t)(tm.tm_min) << 5) |
+ ((acr_uint32_t)(tm.tm_sec) >> 1);
return rv;
}
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=809154&r1=809153&r2=809154&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:29:03 2009
@@ -45,8 +45,10 @@
FileTimeToUsecTime(&aprtime, &ft);
return aprtime;
}
- else
- return 0;
+ else {
+ /* January 1st 1980 as unix time in microseconds */
+ return ACR_INT64_C(315532800000000);
+ }
}
ACR_DECLARE(acr_uint32_t) ACR_Acr2DosTime(acr_time_t t)
@@ -60,6 +62,9 @@
UsecTimeToFileTime(&ft, t * ACR_USEC_PER_SEC);
if (FileTimeToDosDateTime(&ft, &dd, &dt))
return ((acr_uint32_t)dd << 16) | (acr_uint32_t)dt;
- else
- return 0;
+ else {
+ /* January 1st 1980.
+ */
+ return 0x00210000;
+ }
}