r4013 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests

tfheen at projects.linpro.no tfheen at projects.linpro.no
Tue Mar 31 09:44:56 CEST 2009


Author: tfheen
Date: 2009-03-31 09:44:56 +0200 (Tue, 31 Mar 2009)
New Revision: 4013

Added:
   branches/2.0/varnish-cache/bin/varnishtest/tests/r00476.vtc
Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c
Log:
Merge r4002: Allow ESI processing on binary data

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: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c	2009-03-30 13:56:59 UTC (rev 4012)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c	2009-03-31 07:44:56 UTC (rev 4013)
@@ -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);
 }
@@ -512,7 +515,7 @@
 			N(ew);
 			break;
 		}
-	} while (*ew->p.p != '\0');
+	} while (ew->p.p < ew->p.e);
 }
 
 /*--------------------------------------------------------------------*/
@@ -531,7 +534,7 @@
 			N(ew);
 			break;
 		}
-	} while (*ew->p.p != '\0');
+	} while (ew->p.p < ew->p.e);
 }
 
 /*--------------------------------------------------------------------*/
@@ -547,8 +550,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");
@@ -683,11 +686,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 */
@@ -724,7 +728,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);
 			}
 		}
 	}

Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00476.vtc (from rev 4002, trunk/varnish-cache/bin/varnishtest/tests/r00476.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/r00476.vtc	                        (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00476.vtc	2009-03-31 07:44:56 UTC (rev 4013)
@@ -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