X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=parsers.c;h=2650fbb14ab1b4bee5dcabf202aa7af955b4e840;hb=0b26fdd355d5d179b25e7a8da32193aee55ac331;hp=7dbaf028c050a2524ebd5303915197f266500320;hpb=09affc2a8063be4014aba82b095fb7d225b12016;p=privoxy.git diff --git a/parsers.c b/parsers.c index 7dbaf028..2650fbb1 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.228 2011/09/04 11:31:17 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.232 2011/09/04 11:33:50 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -4008,13 +4008,18 @@ int strclean(char *string, const char *substring) static jb_err parse_header_time(const char *header_time, time_t *result) { struct tm gmt; - static const char *time_formats[] = { + /* + * Checking for two-digit years first in an + * attempt to work around GNU libc's strptime() + * reporting negative year values when using %Y. + */ + static const char * const time_formats[] = { + /* Tue, 02-Jun-37 20:00:00 */ + "%a, %d-%b-%y %H:%M:%S", /* Tue, 02 Jun 2037 20:00:00 */ "%a, %d %b %Y %H:%M:%S", /* Tue, 02-Jun-2037 20:00:00 */ "%a, %d-%b-%Y %H:%M:%S", - /* Tue, 02-Jun-37 20:00:00 */ - "%a, %d-%b-%y %H:%M:%S", /* Tuesday, 02-Jun-2037 20:00:00 */ "%A, %d-%b-%Y %H:%M:%S", /* Tuesday Jun 02 20:00:00 2037 */ @@ -4022,16 +4027,24 @@ static jb_err parse_header_time(const char *header_time, time_t *result) }; unsigned int i; - /* - * Zero out gmt to prevent time zone offsets. - * Documented to be required for GNU libc. - */ - memset(&gmt, 0, sizeof(gmt)); - for (i = 0; i < SZ(time_formats); i++) { + /* + * Zero out gmt to prevent time zone offsets. + * Documented to be required for GNU libc. + */ + memset(&gmt, 0, sizeof(gmt)); + if (NULL != strptime(header_time, time_formats[i], &gmt)) { + /* Sanity check for GNU libc. */ + if (gmt.tm_year < 0) + { + log_error(LOG_LEVEL_HEADER, + "Failed to parse '%s' using '%s'. Moving on.", + header_time, time_formats[i]); + continue; + } *result = timegm(&gmt); return JB_ERR_OK; }