[master] 1678f98fa cache_fetch: Fail if storage allocation for synthetic body fails
Nils Goroll
nils.goroll at uplex.de
Sat Apr 12 09:05:06 UTC 2025
commit 1678f98fab599100ebee57328774da9ad8f96460
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Fri Apr 11 14:07:51 2025 +0200
cache_fetch: Fail if storage allocation for synthetic body fails
Fixes #4313
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 2f67446b6..f5a1a1d6a 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -1020,14 +1020,17 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
o = 0;
while (ll > 0) {
l = ll;
- if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
- break;
+ if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK) {
+ VSB_destroy(&synth_body);
+ return (F_STP_FAIL);
+ }
l = vmin(l, ll);
memcpy(ptr, VSB_data(synth_body) + o, l);
VFP_Extend(bo->vfc, l, l == ll ? VFP_END : VFP_OK);
ll -= l;
o += l;
}
+ assert(o == VSB_len(synth_body));
AZ(ObjSetU64(wrk, oc, OA_LEN, o));
VSB_destroy(&synth_body);
ObjSetState(wrk, oc, BOS_PREP_STREAM);
diff --git a/bin/varnishtest/tests/r04313.vtc b/bin/varnishtest/tests/r04313.vtc
new file mode 100644
index 000000000..3a43deff9
--- /dev/null
+++ b/bin/varnishtest/tests/r04313.vtc
@@ -0,0 +1,43 @@
+varnishtest "storage failure with synthetic body"
+
+varnish v1 -arg "-sTransient=debug,maxspace=32B" -vcl {
+ backend none none;
+
+ sub vcl_recv {
+ return(pass);
+ }
+
+ # avoid the client side running into the same storage failure
+ sub vcl_synth {
+ set resp.body = resp.reason;
+ return(deliver);
+ }
+
+ sub vcl_recv {
+ return(pass);
+ }
+
+ sub vcl_backend_error {
+ set beresp.status = 200;
+ set beresp.body =
+ "0123456789abcdef" +
+ "0123456789abcdef" +
+ "X";
+ return (deliver);
+ }
+} -start
+
+logexpect l1 -v v1 -q "vxid == 1002" {
+ fail add * End
+ expect * * Storage {^-sdebug: max_size=32 reached}
+ expect 0 = FetchError {^Could not get storage}
+ fail clear
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 503
+} -run
+
+logexpect l1 -wait
More information about the varnish-commit
mailing list