[3.0] e6e34d2 If the backend used chunked encoding and sent junk after the gzip data, the thread would go into a spin.

Tollef Fog Heen tfheen at varnish-cache.org
Fri Aug 19 12:16:37 CEST 2011


commit e6e34d24b7b2e47d936867a4a1d7714ca568b7ae
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 17 09:33:10 2011 +0000

    If the backend used chunked encoding and sent junk after the gzip
    data, the thread would go into a spin.
    
    Fixes	#942

diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index f320a0a..40a8bdf 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -302,7 +302,7 @@ VGZ_Gunzip(struct vgz *vg, const void **pptr, size_t *plen)
 		return (VGZ_END);
 	if (i == Z_BUF_ERROR)
 		return (VGZ_STUCK);
-printf("INFLATE=%d (%s)\n", i, vg->vz.msg);
+	VSL(SLT_Debug, 0, "Unknown INFLATE=%d (%s)\n", i, vg->vz.msg);
 	return (VGZ_ERROR);
 }
 
@@ -629,6 +629,10 @@ vfp_testgzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 		while (!VGZ_IbufEmpty(vg)) {
 			VGZ_Obuf(vg, obuf, sizeof obuf);
 			i = VGZ_Gunzip(vg, &dp, &dl);
+			if (i == VGZ_END && !VGZ_IbufEmpty(vg)) {
+				WSP(sp, SLT_FetchError, "Junk after gzip data");
+				return (-1);
+			}
 			if (i != VGZ_OK && i != VGZ_END) {
 				WSP(sp, SLT_FetchError,
 				    "Invalid Gzip data: %s", vg->vz.msg);
diff --git a/bin/varnishtest/tests/r00942.vtc b/bin/varnishtest/tests/r00942.vtc
new file mode 100644
index 0000000..0df8eb2
--- /dev/null
+++ b/bin/varnishtest/tests/r00942.vtc
@@ -0,0 +1,38 @@
+varnishtest "#942 junk after gzip from backend"
+
+server s1 {
+	rxreq
+	txresp -nolen \
+		-hdr "Content-Encoding: gzip" \
+		-hdr "Transfer-Encoding: Chunked"
+	send "14\r\n"
+		# An empty gzip file:
+		sendhex "1f8b"
+		sendhex "08"
+		sendhex "00"
+		sendhex "00000000"
+		sendhex "00"
+		sendhex "03"
+		sendhex "0300"
+		sendhex "00000000"
+		sendhex "00000000"
+	send "\r\n"
+
+	chunked "FOOBAR"
+
+	chunkedlen 0
+
+} -start
+
+varnish v1 \
+	-arg {-p diag_bitmap=0x00010000} \
+	-vcl+backend {} 
+
+varnish v1 -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 503
+} -run
+



More information about the varnish-commit mailing list