[master] 1369692 Fix wb_create used by vmod_blob: WS_Reserve of 0 bytes still leaves a reservation

Nils Goroll nils.goroll at uplex.de
Tue Nov 14 09:39:04 UTC 2017


commit 13696927680275144a88767cdd70854d369b2e1c
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Nov 14 10:18:49 2017 +0100

    Fix wb_create used by vmod_blob: WS_Reserve of 0 bytes still leaves a reservation
    
    If workspace was exhausted, vmod_blob would fail yet still leave a
    reservation which would likely trigger a WS_Reserve() assertion
    failure in later code trying to reserve the workspace.
    
    Fixes #2488
    
    Thank you to @jarro2783 for the report and @dridi for the analysis.

diff --git a/bin/varnishtest/tests/r02488.vtc b/bin/varnishtest/tests/r02488.vtc
new file mode 100644
index 0000000..11844a6
--- /dev/null
+++ b/bin/varnishtest/tests/r02488.vtc
@@ -0,0 +1,41 @@
+varnishtest "Test vmod_blob wb_create for empty workspace"
+
+varnish v1 -vcl {
+	import blob;
+	import vtc;
+
+	backend b1 {.host = "${bad_backend}";}
+
+	sub vcl_init {
+		new bl = blob.blob(HEX, "deadbeef");
+	}
+	sub vcl_recv {
+		return (synth(200));
+	}
+	sub vcl_synth {
+		if (req.url == "/empty") {
+			vtc.workspace_alloc(client, -1);
+		}
+		set resp.http.foo = blob.encode(encoding=HEX, blob=bl.get());
+		set resp.http.bar = "bar";
+	}
+} -start
+
+logexpect l1 -v v1 -g raw {
+	expect * 1002 VCL_call	{^SYNTH$}
+	expect 0    = VCL_Error	{^vmod blob error: cannot encode, out of space$}
+	expect 0    = LostHeader	{^foo:$}
+	expect 0    = VCL_return	{^fail$}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.foo == "deadbeef"
+	expect resp.http.bar == "bar"
+
+	txreq -url "/empty"
+	expect_close
+} -run
+
+logexpect l1 -wait
diff --git a/lib/libvmod_blob/wb.c b/lib/libvmod_blob/wb.c
index d56b061..304b12e 100644
--- a/lib/libvmod_blob/wb.c
+++ b/lib/libvmod_blob/wb.c
@@ -35,6 +35,7 @@ char *
 wb_create(struct ws *ws, struct wb_s *wb)
 {
 	if (WS_Reserve(ws, 0) == 0) {
+		WS_Release(ws, 0);
 		wb->w = NULL;
 		wb->ws = NULL;
 		return NULL;


More information about the varnish-commit mailing list