From a2322df85213270c5f6c97dac877c7cfe2689e81 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Wed, 26 Jul 2000 18:44:01 +0000 Subject: [PATCH] Fix a bug in our time parsing. We need to zero out a few fields so that the imploded date is valid. PR: 6266 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85900 13f79535-47bb-0310-9956-ffa450edef68 --- server/util_date.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/util_date.c b/server/util_date.c index 52f3361638..bf782ebad9 100644 --- a/server/util_date.c +++ b/server/util_date.c @@ -201,7 +201,7 @@ API_EXPORT(ap_time_t) ap_parseHTTPdate(const char *date) while (*date && ap_isspace(*date)) /* Find first non-whitespace char */ ++date; - if (*date == '\0') + if (*date == '\0') return BAD_DATE; if ((date = strchr(date, ' ')) == NULL) /* Find space after weekday */ @@ -234,7 +234,7 @@ API_EXPORT(ap_time_t) ap_parseHTTPdate(const char *date) } else if (ap_checkmask(date, "@$$ ~# ##:##:## ####*")) { /* asctime format */ ds.tm_year = ((date[16] - '0') * 10 + (date[17] - '0') - 19) * 100; - if (ds.tm_year < 0) + if (ds.tm_year < 0) return BAD_DATE; ds.tm_year += ((date[18] - '0') * 10) + (date[19] - '0'); @@ -249,7 +249,7 @@ API_EXPORT(ap_time_t) ap_parseHTTPdate(const char *date) monstr = date; timstr = date + 7; } - else + else return BAD_DATE; if (ds.tm_mday <= 0 || ds.tm_mday > 31) @@ -259,7 +259,7 @@ API_EXPORT(ap_time_t) ap_parseHTTPdate(const char *date) ds.tm_min = ((timstr[3] - '0') * 10) + (timstr[4] - '0'); ds.tm_sec = ((timstr[6] - '0') * 10) + (timstr[7] - '0'); - if ((ds.tm_hour > 23) || (ds.tm_min > 59) || (ds.tm_sec > 61)) + if ((ds.tm_hour > 23) || (ds.tm_min > 59) || (ds.tm_sec > 61)) return BAD_DATE; mint = (monstr[0] << 16) | (monstr[1] << 8) | monstr[2]; @@ -284,8 +284,19 @@ API_EXPORT(ap_time_t) ap_parseHTTPdate(const char *date) ds.tm_mon = mon; - if (ap_implode_time(&result, &ds) != APR_SUCCESS) { + /* ap_mplode_time uses tm_usec and tm_gmtoff fields, but they haven't + * been set yet. + * It should be safe to just zero out these values. + * tm_usec is the number of microseconds into the second. HTTP only + * cares about second granularity. + * tm_gmtoff is the number of seconds off of GMT the time is. By + * definition all times going through this function are in GMT, so this + * is zero. + */ + ds.tm_usec = 0; + ds.tm_gmtoff = 0; + if (ap_implode_time(&result, &ds) != APR_SUCCESS) return BAD_DATE; - } + return result; } -- 2.40.0