[master] b2d7538 fix enum check in vcc: do not accept values valid for other arguments

Nils Goroll nils.goroll at uplex.de
Wed Nov 30 17:12:05 CET 2016


commit b2d75389716610c72d333eb5ae4a81cfbdff5b60
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Nov 30 16:42:03 2016 +0100

    fix enum check in vcc: do not accept values valid for other arguments
    
    VCC was silently accepting enum values valid for other arguments
    following in the argument list as well as other identifiers in the
    argument spec (for example "ENUM"). Consequently, wrong enum values in
    VCL were not detected at VCC time and passed to vmod functions, which,
    in the best case, would detect the error (and, if following the
    varnish good practice, panic on a failed assertion).
    
    This is another forgotten case since the enum list was changed to be
    terminated by \1 in a78efad8002895e6097aeb6b1daeac0f6108b9a9: vcc_expr
    would just loop over the \1 terminator up to the final \0 terminator
    at the end of the argument spec.

diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 999b39f..57749aa 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -59,7 +59,14 @@ logexpect l1 -wait
 varnish v1 -errvcl {Wrong enum value.  Expected one of:} {
 	import debug;
 	sub vcl_deliver {
-		set resp.http.who = debug.author(jfk);
+		set resp.http.who = debug.author(ENUM);
+	}
+}
+
+varnish v1 -errvcl {Wrong enum value.  Expected one of:} {
+	import debug;
+	sub vcl_deliver {
+		set resp.http.who = debug.author(slink);
 	}
 }
 
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index e48597b..0aca3da 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -548,8 +548,8 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa)
 			if (vcc_IdIs(tl->t, p))
 				break;
 			p += strlen(p) + 1;
-		} while (*p != '\0');
-		if (*p == '\0') {
+		} while (*p != '\1');
+		if (*p == '\1') {
 			VSB_printf(tl->sb, "Wrong enum value.");
 			VSB_printf(tl->sb, "  Expected one of:\n");
 			do {
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 4cebb1f..204affd 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -39,7 +39,8 @@ $Function VOID panic(STRING_LIST)
 
 Don't.
 
-$Function STRING author(ENUM { phk, des, kristian, mithrandir } person="phk")
+$Function STRING author(ENUM { phk, des, kristian, mithrandir } person="phk",
+			ENUM { phk, slink, geoff } someone="phk")
 
 Test function for ENUM arguments
 
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index a0ab290..6f589e7 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -68,17 +68,18 @@ vmod_panic(VRT_CTX, const char *str, ...)
 }
 
 VCL_STRING __match_proto__(td_debug_author)
-vmod_author(VRT_CTX, VCL_ENUM id)
+vmod_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone)
 {
+	(void)someone;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	if (!strcmp(id, "phk"))
+	if (!strcmp(person, "phk"))
 		return ("Poul-Henning");
-	if (!strcmp(id, "des"))
+	if (!strcmp(person, "des"))
 		return ("Dag-Erling");
-	if (!strcmp(id, "kristian"))
+	if (!strcmp(person, "kristian"))
 		return ("Kristian");
-	if (!strcmp(id, "mithrandir"))
+	if (!strcmp(person, "mithrandir"))
 		return ("Tollef");
 	WRONG("Illegal VMOD enum");
 }



More information about the varnish-commit mailing list