[master] 0a6e8a6 Deal with any remaining request body in cnt_synth

Martin Blix Grydeland martin at varnish-software.com
Mon Aug 25 13:01:25 CEST 2014


commit 0a6e8a6cac45ee56a3f69f0e8f3ad4df23d33250
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri Aug 22 15:40:44 2014 +0200

    Deal with any remaining request body in cnt_synth
    
    Call HTTP1_DiscardReqBody() in cnt_synth before delivery to deal with
    any lingering request body.
    
    Fixes: #1577

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 7ab29ac..0e5d188 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -220,7 +220,6 @@ cnt_synth(struct worker *wrk, struct req *req)
 
 	wrk->stats.s_synth++;
 
-
 	now = W_TIM_real(wrk);
 	VSLb_ts_req(req, "Process", now);
 
@@ -257,6 +256,9 @@ cnt_synth(struct worker *wrk, struct req *req)
 	if (http_HdrIs(req->resp, H_Connection, "close"))
 		req->doclose = SC_RESP_CLOSE;
 
+	/* Discard any lingering request body before delivery */
+	(void)HTTP1_DiscardReqBody(req);
+
 	V1D_Deliver_Synth(req);
 
 	VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
diff --git a/bin/varnishtest/tests/r01577.vtc b/bin/varnishtest/tests/r01577.vtc
new file mode 100644
index 0000000..9a90ed5
--- /dev/null
+++ b/bin/varnishtest/tests/r01577.vtc
@@ -0,0 +1,37 @@
+varnishtest "#1577: reqbody and synth from recv"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.url == "/1") {
+			return (synth(200, "OK"));
+		}
+	}
+	sub vcl_synth {
+		set resp.http.x-url = req.url;
+	}
+	sub vcl_deliver {
+		set resp.http.x-url = req.url;
+	}
+} -start
+
+client c1 {
+	# Send a body that happens to be a valid HTTP request
+	# This one is answered by synth()
+	txreq -url "/1" -body "GET /foo HTTP/1.1\r\n\r\n"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.x-url == "/1"
+
+	# Make sure that a second request on the same connection goes through
+	# and that the body of the previous one isn't interpreted as the
+	# next request
+	txreq -url "/2"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.x-url == "/2"
+} -run



More information about the varnish-commit mailing list