Skip to content
Browse files

This patch adds support for an additional, but invalid, data format:

"wdy, DD mth YYYY HH:MM:SS +0000". Thanks to Antonio Perez for the
report and initial patch!

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6378 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent 17005c4 commit ff9a881b9423add7e4faa1520d9f8ebec43e42dd @alobbs alobbs committed Mar 8, 2011
Showing with 29 additions and 24 deletions.
  1. +26 −21 cherokee/dtm.c
  2. +1 −1 cherokee/dtm.h
  3. +2 −2 cherokee/handler_file.c
View
47 cherokee/dtm.c
@@ -551,11 +551,12 @@ cvt_tm2time( struct tm *ptm )
* ret_deny - Parsed an invalid date
*/
ret_t
-cherokee_dtm_str2time (char* cstr, time_t *time)
+cherokee_dtm_str2time (char* cstr, int cstr_len, time_t *time)
{
- struct tm tm;
- char *psz = cstr;
- size_t idx = 0;
+ struct tm tm;
+ char *psz = cstr;
+ size_t idx = 0;
+ const char *cstr_end = cstr + cstr_len;
/* Zero struct tm.
*/
@@ -586,6 +587,7 @@ cherokee_dtm_str2time (char* cstr, time_t *time)
/* -----------------------------
* wdy, DD mth YYYY HH:MM:SS GMT
+ * wdy, DD mth YYYY HH:MM:SS +0000
* wdy, DD-mth-YY HH:MM:SS GMT
* -----------------------------
*/
@@ -657,31 +659,35 @@ cherokee_dtm_str2time (char* cstr, time_t *time)
/* Deformat hours, minutes, seconds.
*/
- if (!isdigit( psz[0] ) || !isdigit( psz[1] ) ||
- psz[2] != ':' ||
- !isdigit( psz[3] ) || !isdigit( psz[4] ) ||
- psz[5] != ':' ||
- !isdigit( psz[6] ) || !isdigit( psz[7] )
- ) {
+ if ((cstr_end - psz < 7)||
+ (! isdigit (psz[0]) || ! isdigit (psz[1]) || psz[2] != ':' ||
+ ! isdigit (psz[3]) || ! isdigit (psz[4]) || psz[5] != ':' ||
+ ! isdigit (psz[6]) || ! isdigit (psz[7])))
+ {
return ret_error;
}
+
tm.tm_hour = (psz[0] - '0') * 10 + (psz[1] - '0');
tm.tm_min = (psz[3] - '0') * 10 + (psz[4] - '0');
tm.tm_sec = (psz[6] - '0') * 10 + (psz[7] - '0');
/* Skip field separator(s).
*/
idx += 8;
- while( psz[idx] == ' ')
+ while (psz[idx] == ' ')
++idx;
psz += idx;
idx = 0;
/* Time Zone (always Greenwitch Mean Time)
*/
- if ( psz[0] != 'G' ||
- psz[1] != 'M' ||
- psz[2] != 'T') {
+ if (cstr_end - psz < 3) {
+ return ret_error;
+ }
+
+ if ((psz[0] != 'G' || psz[1] != 'M' || psz[2] != 'T') &&
+ (psz[0] != '+' || psz[1] != '0' || psz[2] != '0'))
+ {
return ret_error;
}
@@ -739,15 +745,14 @@ cherokee_dtm_str2time (char* cstr, time_t *time)
/* Deformat hours, minutes, seconds.
*/
- if (
- !isdigit( psz[0] ) || !isdigit( psz[1] ) ||
- psz[2] != ':' ||
- !isdigit( psz[3] ) || !isdigit( psz[4] ) ||
- psz[5] != ':' ||
- !isdigit( psz[6] ) || !isdigit( psz[7] )
- ) {
+ if ((cstr_end - psz < 7)||
+ (! isdigit (psz[0]) || ! isdigit (psz[1]) || psz[2] != ':' ||
+ ! isdigit (psz[3]) || ! isdigit (psz[4]) || psz[5] != ':' ||
+ ! isdigit (psz[6]) || ! isdigit (psz[7])))
+ {
return ret_error;
}
+
tm.tm_hour = (psz[0] - '0') * 10 + (psz[1] - '0');
tm.tm_min = (psz[3] - '0') * 10 + (psz[4] - '0');
tm.tm_sec = (psz[6] - '0') * 10 + (psz[7] - '0');
View
2 cherokee/dtm.h
@@ -48,7 +48,7 @@ char *cherokee_dtm_wday_name (int idxName);
const
char *cherokee_dtm_month_name(int idxName);
-ret_t cherokee_dtm_str2time (char* cstr, time_t *time);
+ret_t cherokee_dtm_str2time (char *cstr, int cstr_len, time_t *time);
size_t cherokee_dtm_gmttm2str (char *bufstr, size_t bufsize, struct tm *ptm);
CHEROKEE_END_DECLS
View
4 cherokee/handler_file.c
@@ -179,7 +179,7 @@ check_cached (cherokee_handler_file_t *fhdl)
/* Parse the Date string
*/
- ret = cherokee_dtm_str2time (header, &req_time);
+ ret = cherokee_dtm_str2time (header, header_len, &req_time);
if (unlikely (ret == ret_error)) {
LOG_WARNING (CHEROKEE_ERROR_HANDLER_FILE_TIME_PARSE, header);
@@ -269,7 +269,7 @@ check_cached (cherokee_handler_file_t *fhdl)
else {
time_t req_time = 0;
- ret = cherokee_dtm_str2time (header, &req_time);
+ ret = cherokee_dtm_str2time (header, header_len, &req_time);
if (unlikely (ret == ret_error)) {
LOG_WARNING (CHEROKEE_ERROR_HANDLER_FILE_TIME_PARSE, header);

0 comments on commit ff9a881

Please sign in to comment.
Something went wrong with that request. Please try again.