[master] 66c8c9c Treat RFC-illegal negative (s-)max-age values as zero.
Poul-Henning Kamp
phk at varnish-cache.org
Thu Mar 31 13:24:28 CEST 2011
commit 66c8c9c358bc85f0601f03eb175e01da79251733
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Mar 31 11:24:05 2011 +0000
Treat RFC-illegal negative (s-)max-age values as zero.
Fixes #887
diff --git a/bin/varnishd/rfc2616.c b/bin/varnishd/rfc2616.c
index 2c6c851..d581444 100644
--- a/bin/varnishd/rfc2616.c
+++ b/bin/varnishd/rfc2616.c
@@ -112,7 +112,10 @@ RFC2616_Ttl(const struct sess *sp)
http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) &&
p != NULL) {
- max_age = strtoul(p, NULL, 0);
+ if (*p == '-')
+ max_age = 0;
+ else
+ max_age = strtoul(p, NULL, 0);
if (http_GetHdr(hp, H_Age, &p)) {
age = strtoul(p, NULL, 0);
sp->wrk->age = age;
diff --git a/bin/varnishtest/tests/r00887.vtc b/bin/varnishtest/tests/r00887.vtc
new file mode 100644
index 0000000..697be6e
--- /dev/null
+++ b/bin/varnishtest/tests/r00887.vtc
@@ -0,0 +1,22 @@
+# $Id$
+
+test "Ticket #887"
+
+server s1 {
+ rxreq
+ txresp -hdr "Cache-control: max-age=-1000" -body "FOO"
+ rxreq
+ txresp -body "FOOBAR"
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.bodylen == 3
+ txreq
+ rxresp
+ expect resp.bodylen == 6
+} -run
More information about the varnish-commit
mailing list