[master] 96913be Fail gracefully if shard.backend() is called in housekeeping subs

Nils Goroll nils.goroll at uplex.de
Tue Nov 28 12:46:07 UTC 2017


commit 96913becedb1e1c98bac6b649350d4b33da2ec24
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Nov 28 13:42:28 2017 +0100

    Fail gracefully if shard.backend() is called in housekeeping subs
    
    Fixes #2506

diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 984c3ed..1893142 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -33,6 +33,7 @@
 #include <string.h>
 
 #include "cache/cache.h"
+#include "vcl.h"
 
 #include "vend.h"
 
@@ -234,6 +235,13 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC);
 
+	/* TODO #2500 */
+	if ((ctx->method & (VCL_MET_TASK_C | VCL_MET_TASK_B)) == 0) {
+		VRT_fail(ctx, "shard .backend() method may only be used "
+			 "in client and backend context");
+		return NULL;
+	}
+
 	if (key_int && by != BY_KEY) {
 		shard_err(ctx, vshard->shardd,
 		    "by=%s but key argument used", by_s);


More information about the varnish-commit mailing list