[3.0] c9db023 Return false if req.backend.health is accessed in vcl_deliver{} where this information is no longer available.
Tollef Fog Heen
tfheen at varnish-cache.org
Mon Apr 22 13:27:01 CEST 2013
commit c9db023f8c83f9f11199e09073ccfd8ecd320181
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Apr 9 13:05:14 2013 +0200
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_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index 9a2e500..189d8e9 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -536,6 +536,12 @@ unsigned
VRT_r_req_backend_healthy(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ /*
+ * XXX: Not optimal, but we do not have a backend in vcl_deliver
+ * XXX: and we have to return something.
+ */
+ if (sp->director == NULL)
+ return (0);
CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
return (VDI_Healthy(sp->director, sp));
}
diff --git a/bin/varnishtest/tests/r01228.vcl b/bin/varnishtest/tests/r01228.vcl
new file mode 100644
index 0000000..33bf365
--- /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