[master] 1706409 Half of #2088 is solved

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Feb 3 17:39:05 CET 2017


commit 1706409325fed0d464f50add5c72acb5d8e35c6b
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Feb 3 15:57:01 2017 +0100

    Half of #2088 is solved
    
    See 9849fd0 for how it was solved.

diff --git a/bin/varnishtest/tests/m00027.vtc b/bin/varnishtest/tests/m00027.vtc
new file mode 100644
index 0000000..92cd417
--- /dev/null
+++ b/bin/varnishtest/tests/m00027.vtc
@@ -0,0 +1,25 @@
+varnishtest "Test object initialization failure"
+
+server s1 { } -start
+
+varnish v1 -vcl+backend { } -start
+
+varnish v1 -errvcl "Missing dynamic backend address or port" {
+	import debug;
+	import std;
+
+	backend be {
+		.host = "${bad_backend}";
+	}
+
+	sub vcl_init {
+		new obj = debug.dyn("", "");
+		std.log("Should not happen");
+	}
+}
+
+shell -err {
+	set -e
+	varnishlog -n ${v1_name} -d -g raw >v1.log
+	! grep "Should not happen" v1.log
+}
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index ca61e45..a9d7d57 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -153,7 +153,7 @@ Sleep the current worker thread.
 
 $Object dyn(STRING addr, STRING port)
 
-Dynamically create a single-backend director
+Dynamically create a single-backend director, addr and port must not be empty.
 
 $Method BACKEND .backend()
 
diff --git a/lib/libvmod_debug/vmod_debug_dyn.c b/lib/libvmod_debug/vmod_debug_dyn.c
index 03610ee..b2d87f6 100644
--- a/lib/libvmod_debug/vmod_debug_dyn.c
+++ b/lib/libvmod_debug/vmod_debug_dyn.c
@@ -117,6 +117,14 @@ vmod_dyn__init(VRT_CTX, struct vmod_debug_dyn **dynp,
 	AZ(*dynp);
 	AN(vcl_name);
 
+	if (*addr == '\0' || *port == '\0') {
+		AN(ctx->handling);
+		AZ(*ctx->handling);
+		VSB_printf(ctx->msg, "Missing dynamic backend address or port");
+		VRT_handling(ctx, VCL_RET_FAIL);
+		return;
+	}
+
 	ALLOC_OBJ(dyn, VMOD_DEBUG_DYN_MAGIC);
 	AN(dyn);
 	REPLACE(dyn->vcl_name, vcl_name);
@@ -134,6 +142,9 @@ vmod_dyn__fini(struct vmod_debug_dyn **dynp)
 	struct vmod_debug_dyn *dyn;
 
 	AN(dynp);
+	if (*dynp == NULL)
+		return; /* failed initialization */
+
 	CAST_OBJ_NOTNULL(dyn, *dynp, VMOD_DEBUG_DYN_MAGIC);
 	/* at this point all backends will be deleted by the vcl */
 	free(dyn->vcl_name);



More information about the varnish-commit mailing list