r4002 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

sky at projects.linpro.no sky at projects.linpro.no
Tue Mar 24 13:28:01 CET 2009


Author: sky
Date: 2009-03-24 13:28:01 +0100 (Tue, 24 Mar 2009)
New Revision: 4002

Added:
   trunk/varnish-cache/bin/varnishtest/tests/r00476.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_esi.c
Log:
Fix for bug 476 -- ESI was using null chars to deal with the strings, this made it impossible to pass binary CDATA through the ESI parser. This switches it to compare against the end pointer of the string. Test case attached.

Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-03-24 08:30:08 UTC (rev 4001)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-03-24 12:28:01 UTC (rev 4002)
@@ -71,6 +71,7 @@
 
 struct esi_ptr {
 	const char		*p;
+	const char              *e;
 	struct storage		*st;
 };
 
@@ -108,9 +109,11 @@
 	ep->st = VTAILQ_NEXT(ep->st, list);
 	if (ep->st != NULL) {
 		ep->p = (char *)ep->st->ptr;
+		ep->e = ep->p + ep->st->len;
 		return;
 	}
 	ep->p = finis;
+	ep->e = finis;
 	return;
 }
 
@@ -118,7 +121,7 @@
 N(struct esi_work *ew)
 {
 
-	if (*ew->p.p != '\0')
+	if (ew->p.p < ew->p.e)
 		ew->off++;
 	Nep(&ew->p);
 }
@@ -511,7 +514,7 @@
 			N(ew);
 			break;
 		}
-	} while (*ew->p.p != '\0');
+	} while (ew->p.p < ew->p.e);
 }
 
 /*--------------------------------------------------------------------*/
@@ -530,7 +533,7 @@
 			N(ew);
 			break;
 		}
-	} while (*ew->p.p != '\0');
+	} while (ew->p.p < ew->p.e);
 }
 
 /*--------------------------------------------------------------------*/
@@ -546,8 +549,8 @@
 
 	do
 		N(ew);
-	while (*ew->p.p != '>' && *ew->p.p != '\0');
-	if (*ew->p.p == '\0') {
+	while (*ew->p.p != '>' && ew->p.p < ew->p.e);
+	if (ew->p.p == ew->p.e) {
 		esi_addpfx(ew);
 		esi_error(ew, ew->s.p, 0,
 		    "XML 1.0 incomplete language element");
@@ -675,11 +678,12 @@
 	ew->p.st = VTAILQ_FIRST(&sp->obj->store);
 	AN(ew->p.st);
 	ew->p.p = (char *)ew->p.st->ptr;
-
+	ew->p.e = ew->p.p + ew->p.st->len;
+	
 	/* ->s points to the first un-dealt-with byte */
 	ew->s = ew->p;
 
-	while (*ew->p.p != '\0') {
+	while (ew->p.p < ew->p.e) {
 
 		if (ew->incmt && *ew->p.p == '-' && !CMP(&ew->p, "-->")) {
 			/* End of ESI comment */
@@ -716,7 +720,7 @@
 				/* XXX: drop this ? */
 				do {
 					N(ew);
-				} while (*ew->p.p != '>' && *ew->p.p != '\0');
+				} while (*ew->p.p != '>' && ew->p.p < ew->p.e);
 			}
 		}
 	}

Added: trunk/varnish-cache/bin/varnishtest/tests/r00476.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/r00476.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/r00476.vtc	2009-03-24 12:28:01 UTC (rev 4002)
@@ -0,0 +1,36 @@
+# $Id: r00445.vtc 3987 2009-03-23 11:54:19Z sky $
+
+test "zero length ESI include segmens with chunked encoding"
+
+server s1 {
+	rxreq
+	expect req.url == "/"
+	txresp -body {<a><esi:include src="/bar"><b>\0c}
+	rxreq
+	expect req.url == "/bar"
+	txresp 
+	rxreq
+	expect req.url == "/comment"
+	txresp -body {<a><!--esi foo --><b>\0c}
+	rxreq
+	expect req.url == "/nullbefore"
+	txresp -body {<a>\0<esi:include src="/bar"><b>c}
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_fetch {
+		esi;
+	}
+} -start
+
+client c1 {
+	txreq 
+	rxresp
+	expect resp.bodylen == 8
+	txreq -url /comment
+	rxresp
+	expect resp.bodylen == 13
+	txreq -url /nullbefore
+	rxresp
+	expect resp.bodylen == 8
+} -run



More information about the varnish-commit mailing list