From fa3ced18fd055338536a2e9f69560dd0da8e826f Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Fri, 31 Aug 2018 16:42:15 +0000 Subject: Resolve invalid rvalue from void() function, the test is only required in one single case of user-provided input, to avoid an index into invalid memory. Backports: 1839769 git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1839771 13f79535-47bb-0310-9956-ffa450edef68 --- time/win32/time.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/time/win32/time.c b/time/win32/time.c index 1a705443b..6f4590541 100644 --- a/time/win32/time.c +++ b/time/win32/time.c @@ -54,9 +54,6 @@ static void SystemTimeToAprExpTime(apr_time_exp_t *xt, SYSTEMTIME *tm) static const int dayoffset[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - if (tm->wMonth < 1 || tm->wMonth > 12) - return APR_EBADDATE; - /* Note; the caller is responsible for filling in detailed tm_usec, * tm_gmtoff and tm_isdst data when applicable. */ @@ -111,6 +108,7 @@ APR_DECLARE(apr_status_t) apr_time_exp_gmt(apr_time_exp_t *result, FileTimeToSystemTime(&ft, &st); /* The Platform SDK documents that SYSTEMTIME/FILETIME are * generally UTC, so no timezone info needed + * The time value makes a roundtrip, st cannot be invalid below. */ SystemTimeToAprExpTime(result, &st); result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC); @@ -127,6 +125,7 @@ APR_DECLARE(apr_status_t) apr_time_exp_tz(apr_time_exp_t *result, FileTimeToSystemTime(&ft, &st); /* The Platform SDK documents that SYSTEMTIME/FILETIME are * generally UTC, so we will simply note the offs used. + * The time value makes a roundtrip, st cannot be invalid below. */ SystemTimeToAprExpTime(result, &st); result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC); @@ -158,6 +157,7 @@ APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result, * because FileTimeToLocalFileFime is documented that the * resulting time local file time would have DST relative * to the *present* date, not the date converted. + * The time value makes a roundtrip, localst cannot be invalid below. */ SystemTimeToTzSpecificLocalTime(tz, &st, &localst); SystemTimeToAprExpTime(result, &localst); @@ -187,6 +187,7 @@ APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result, TIME_ZONE_INFORMATION tz; /* XXX: This code is simply *wrong*. The time converted will always * map to the *now current* status of daylight savings time. + * The time value makes a roundtrip, st cannot be invalid below. */ FileTimeToLocalFileTime(&ft, &localft); @@ -298,6 +299,9 @@ APR_DECLARE(apr_status_t) apr_os_exp_time_put(apr_time_exp_t *aprtime, /* The Platform SDK documents that SYSTEMTIME/FILETIME are * generally UTC, so no timezone info needed */ + if (tm->wMonth < 1 || tm->wMonth > 12) + return APR_EBADDATE; + SystemTimeToAprExpTime(aprtime, *ostime); return APR_SUCCESS; } -- cgit v1.2.1