[master] 60b5e71 Properly complain if people try to reuse symbols.

Poul-Henning Kamp phk at FreeBSD.org
Mon May 26 10:40:16 CEST 2014


commit 60b5e71e8a59a53f2575802c30a2f6eb2b7d2336
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 26 08:39:50 2014 +0000

    Properly complain if people try to reuse symbols.
    
    Fixes #1510

diff --git a/bin/varnishtest/tests/r01510.vtc b/bin/varnishtest/tests/r01510.vtc
new file mode 100644
index 0000000..e8933be
--- /dev/null
+++ b/bin/varnishtest/tests/r01510.vtc
@@ -0,0 +1,19 @@
+varnishtest "Duplicate object names"
+
+varnish v1 -errvcl {Object name 'first' already used.} {
+	import ${vmod_debug};
+	sub vcl_init {
+		new first = debug.obj("FOO");
+		new first = debug.obj("BAH");
+	}
+} 
+
+varnish v1 -errvcl {Object name 'first' already used.} {
+	import ${vmod_debug};
+
+	backend first { .host = "${bad_ip}"; }
+
+	sub vcl_init {
+		new first = debug.obj("FOO");
+	}
+} 
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 910a89c..745f5b4 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -164,10 +164,25 @@ parse_new(struct vcc *tl)
 		return;
 	}
 	sy1 = VCC_FindSymbol(tl, tl->t, SYM_NONE);
+	if (sy1 != NULL) {
+		VSB_printf(tl->sb, "Object name '%.*s' already used.\n",
+		    PF(tl->t));
+
+		VSB_printf(tl->sb, "First usage:\n");
+		AN(sy1->def_b);
+		if (sy1->def_e != NULL)
+			vcc_ErrWhere2(tl, sy1->def_b, sy1->def_e);
+		else
+			vcc_ErrWhere(tl, sy1->def_b);
+		VSB_printf(tl->sb, "Redefinition:\n");
+		vcc_ErrWhere(tl, tl->t);
+		return;
+	}
 	XXXAZ(sy1);
 
 	sy1 = VCC_AddSymbolTok(tl, tl->t, SYM_NONE);	// XXX: NONE ?
 	XXXAN(sy1);
+	sy1->def_b = tl->t;
 	vcc_NextToken(tl);
 
 	ExpectErr(tl, '=');
@@ -243,6 +258,7 @@ parse_new(struct vcc *tl)
 		}
 		p += 2;
 	}
+	sy1->def_e = tl->t;
 	/*lint -restore */
 }
 



More information about the varnish-commit mailing list