Commit b2d75389 authored by Nils Goroll's avatar Nils Goroll

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 a78efad8: vcc_expr
would just loop over the \1 terminator up to the final \0 terminator
at the end of the argument spec.
parent 2a450be4
......@@ -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);
}
}
......
......@@ -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 {
......
......@@ -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
......
......@@ -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");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment