[master] 7db894f Return false if req.backend.health is accessed in vcl_deliver{} where this information is no longer available.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Nov 12 09:14:58 CET 2012
commit 7db894f93330eed1da99336f69a3073a9629eeab
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Nov 12 08:14:11 2012 +0000
Return false if req.backend.health is accessed in vcl_deliver{} where
this information is no longer available.
Fixes #1228
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 535e5ee..76c17d6 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -555,6 +555,12 @@ unsigned
VRT_r_req_backend_healthy(const struct req *req)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ /*
+ * XXX: Not optimal, but we do not have a backend in vcl_deliver
+ * XXX: and we have to return something.
+ */
+ if (req->director == NULL)
+ return (0);
CHECK_OBJ_NOTNULL(req->director, DIRECTOR_MAGIC);
return (VDI_Healthy(req->director, req));
}
diff --git a/bin/varnishtest/tests/r01228.vcl b/bin/varnishtest/tests/r01228.vcl
new file mode 100644
index 0000000..55d5689
--- /dev/null
+++ b/bin/varnishtest/tests/r01228.vcl
@@ -0,0 +1,18 @@
+varnishtest "req.backend.healthy in vcl_deliver"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_deliver {
+ set resp.http.x-foo = req.backend.healthy;
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+} -run
More information about the varnish-commit
mailing list