[master] 505b7bd96 WS_ReserveSize() must not hold a reservation for zero return value
Nils Goroll
nils.goroll at uplex.de
Tue Nov 26 12:44:06 UTC 2019
commit 505b7bd9643006fa8e3977f920564ce12a2b24a2
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 #3131
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 7b1b6d8f8..a40bdbc1b 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -261,7 +261,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..8834e50f7
--- /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 None;
+
+ 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
diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc
index 4f15d0d07..d111f9eb6 100644
--- a/lib/libvmod_vtc/vmod.vcc
+++ b/lib/libvmod_vtc/vmod.vcc
@@ -102,7 +102,7 @@ $Function BYTES workspace_reserve(ENUM { client, backend, session, thread },
Attempt to reserve *size* bytes and release the reservation right
away. Return the size of the reservation.
-See `vtc.workspace_alloc`_ for semantics of the *size* argument.
+See `vtc.workspace_alloc()`_ for semantics of the *size* argument.
$Function INT workspace_free(ENUM { client, backend, session, thread })
More information about the varnish-commit
mailing list