Commit 13696927 authored by Nils Goroll's avatar Nils Goroll

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.
parent 5b81596e
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
...@@ -35,6 +35,7 @@ char * ...@@ -35,6 +35,7 @@ char *
wb_create(struct ws *ws, struct wb_s *wb) wb_create(struct ws *ws, struct wb_s *wb)
{ {
if (WS_Reserve(ws, 0) == 0) { if (WS_Reserve(ws, 0) == 0) {
WS_Release(ws, 0);
wb->w = NULL; wb->w = NULL;
wb->ws = NULL; wb->ws = NULL;
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment