Permalink
Browse files

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.
  • Loading branch information...
nigoroll committed Nov 14, 2017
1 parent 5b81596 commit 13696927680275144a88767cdd70854d369b2e1c
Showing with 42 additions and 0 deletions.
  1. +41 −0 bin/varnishtest/tests/r02488.vtc
  2. +1 −0 lib/libvmod_blob/wb.c
@@ -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
View
@@ -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;

0 comments on commit 1369692

Please sign in to comment.