Hi,
Several weeks ago after a peek at the log file I noticed polipo was
failing to parse last-modified headers with alarming frequency. It
would seem a great number of sites I visit fail to add the timezone
to the end of the date. This was resolved easy enough with the first
patch (no-timezone.patch).
This obviously just checks if we've reached the end of the available
buffer before checking for the timezone.
The second problem I noticed was with timezone offsets that
follow the time.
e.g.
Wed, 17 Sep 1975 21:32:10 +0400 GMT
The second patch (gmtoff.patch) solves this. It should handle offset
values in any
of the following forms:
{+,-}HH
{+,-}HHMM
{+,-}HH:MM
I've been using this for the past week or so and have yet to notice any
ill effects. If you see something I didn't please tell me as I keep a
decent sized cache. I don't like the idea that all the dates are wrong.
The second patch contains the changes made in the first so there is no need
to apply them both. The differences are against the current head:
20090427200152-4cc09-e7b002c90da52db1ad504a1ebb5c65fdeef68563.gz
Thanks
- Adam
diff --git a/parse_time.c b/parse_time.c
index 71109b2..6c1058f 100644
--- a/parse_time.c
+++ b/parse_time.c
@@ -160,8 +160,10 @@ parse_time(const char *buf, int offset, int len, time_t *time_return)
i = parse_int(buf, i, len, &tm.tm_min); if(i < 0) return -1;
i = skip_separator(buf, i, len); if(i < 0) return -1;
i = parse_int(buf, i, len, &tm.tm_sec); if(i < 0) return -1;
- i = skip_separator(buf, i, len); if(i < 0) return -1;
- i = skip_word(buf, i, len); if(i < 0) return -1;
+ if(i < len) {
+ i = skip_separator(buf, i, len); if(i < 0) return -1;
+ i = skip_word(buf, i, len); if(i < 0) return -1;
+ }
} else { /* funny American format */
i = parse_month(buf, i, len, &tm.tm_mon); if(i < 0) return -1;
i = skip_separator(buf, i, len); if(i < 0) return -1;
diff --git a/parse_time.c b/parse_time.c
index 71109b2..101e3d6 100644
--- a/parse_time.c
+++ b/parse_time.c
@@ -128,12 +128,47 @@ skip_separator(const char *buf, int i, int len)
return i;
}
+static int
+parse_gmtoff(const char *buf, int i, int len, long *val_return)
+{
+ int neg, h = 0, m = 0;
+ long sdiff;
+
+ if(i + 3 > len)
+ return -1;
+
+ neg = buf[i++] == '-';
+
+ i = parse_int(buf, i, i+2, &h);
+ if(i < 0 || h >= 24)
+ return -1;
+
+ /* minutes are optional */
+ if(i + 2 <= len) {
+ if(buf[i] == ':')
+ i++;
+ if(d2i(buf[i]) >= 0) {
+ i = parse_int(buf, i, i+2, &m);
+ if(i < 0 || m >= 60)
+ return -1;
+ }
+ }
+
+ sdiff = h * 60 * 60 + m * 60;
+ if(neg && sdiff)
+ sdiff = ~sdiff + 1;
+
+ *val_return = sdiff;
+ return i;
+}
+
int
parse_time(const char *buf, int offset, int len, time_t *time_return)
{
struct tm tm;
time_t t;
int i = offset;
+ long gmtoff = 0;
i = skip_word(buf, i, len); if(i < 0) return -1;
i = skip_separator(buf, i, len); if(i < 0) return -1;
@@ -160,8 +195,20 @@ parse_time(const char *buf, int offset, int len, time_t *time_return)
i = parse_int(buf, i, len, &tm.tm_min); if(i < 0) return -1;
i = skip_separator(buf, i, len); if(i < 0) return -1;
i = parse_int(buf, i, len, &tm.tm_sec); if(i < 0) return -1;
- i = skip_separator(buf, i, len); if(i < 0) return -1;
- i = skip_word(buf, i, len); if(i < 0) return -1;
+ if(i < len) {
+ i = skip_separator(buf, i, len); if(i < 0 || i >= len) return -1;
+ if(buf[i] == '+' || buf[i-1] == '-') {
+ i = parse_gmtoff(buf, (buf[i] == '+' ? i : i-1), len, &gmtoff);
+ if(i < 0)
+ return -1;
+ if(i < len) {
+ i = skip_separator(buf, i, len); if(i < 0) return -1;
+ i = skip_word(buf, i, len); if(i < 0) return -1;
+ }
+ } else {
+ i = skip_word(buf, i, len); if(i < 0) return -1;
+ }
+ }
} else { /* funny American format */
i = parse_month(buf, i, len, &tm.tm_mon); if(i < 0) return -1;
i = skip_separator(buf, i, len); if(i < 0) return -1;
@@ -188,6 +235,7 @@ parse_time(const char *buf, int offset, int len, time_t *time_return)
t = mktime_gmt(&tm);
if(t == -1)
return -1;
+ t += gmtoff;
} else {
t = time_t_max;
}
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Polipo-users mailing list
Polipo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/polipo-users