[6.2] ccc936474 WS_ReserveSize() must not hold a reservation for zero return value

Martin Blix Grydeland martin at varnish-software.com
Tue Feb 4 10:03:08 UTC 2020


commit ccc936474ce64d710394df3565efaf48a8169b8e
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Nov 26 13:27:09 2019 +0100

    WS_ReserveSize() must not hold a reservation for zero return value
    
    This originates from a3d47c258fb7938f67a053f6d041257edb69afe9, but
    was overlooked in 4e33359772a3d751b2ef4b5c4b40259f1bcd6903:
    
    When there is insufficient space to fulfil the reservation request, we
    must not leave the workspace reserved.
    
    Fixes varnishcache/varnish-cache#3131
    
    (cherry picked from commit 505b7bd9643006fa8e3977f920564ce12a2b24a2)

diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 7b8df6d23..e98e2cc69 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -262,7 +262,7 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
 	if (bytes < b2)
 		b2 = PRNDUP(bytes);
 
-	if (ws->f + b2 > ws->e) {
+	if (ws->f + b2 >= ws->e) {
 		WS_MarkOverflow(ws);
 		return (0);
 	}
diff --git a/bin/varnishtest/tests/r03131.vtc b/bin/varnishtest/tests/r03131.vtc
new file mode 100644
index 000000000..2722b748a
--- /dev/null
+++ b/bin/varnishtest/tests/r03131.vtc
@@ -0,0 +1,24 @@
+varnishtest "Test workspace functions in vmod_vtc"
+
+varnish v1 -vcl {
+	import vtc;
+	import std;
+
+	backend dummy {.host = "${bad_backend}"; }
+
+	sub vcl_recv {
+		return (synth(200));
+	}
+
+	sub vcl_synth {
+		set resp.http.res1 = vtc.workspace_reserve(client, 1024 * 1024);
+		vtc.workspace_alloc(client, -1);
+		set resp.http.res2 = vtc.workspace_reserve(client, 8);
+		set resp.http.res3 = vtc.workspace_reserve(client, 8);
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+} -run


More information about the varnish-commit mailing list