[master] c9d1478 Be a bit more helpful with the VCC error messages with the names which are restricted to valid C language names.
Poul-Henning Kamp
phk at varnish-cache.org
Fri Jun 14 22:23:39 CEST 2013
commit c9d1478f0cce0891896bcaf03bdf67ae5bd81594
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Jun 14 20:22:38 2013 +0000
Be a bit more helpful with the VCC error messages with the names
which are restricted to valid C language names.
Fixes #1310
diff --git a/bin/varnishtest/tests/m00010.vtc b/bin/varnishtest/tests/m00010.vtc
index 63ba40d..c4c1b3d 100644
--- a/bin/varnishtest/tests/m00010.vtc
+++ b/bin/varnishtest/tests/m00010.vtc
@@ -22,6 +22,13 @@ server s4 {
txresp -body "4444"
} -start
+varnish v1 -errvcl {Names of VCL objects cannot contain '-'} {
+ import directors from "${topbuild}/lib/libvmod_directors/.libs/libvmod_directors.so" ;
+ backend b1 { .host = "127.0.0.1"; .port = "8080";}
+ sub vcl_init {
+ new rr1-xx = directors.round_robin();
+ }
+}
varnish v1 -vcl+backend {
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 2977c85..2cf3f94 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -247,3 +247,31 @@ varnish v1 -vcl {
}
}
}
+
+varnish v1 -errvcl {Names of VCL sub's cannot contain '-'} {
+ backend b { .host = "127.0.0.1"; }
+ sub foo-bar {
+ }
+ sub vcl_recv {
+ call foo-bar;
+ }
+}
+
+varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} {
+ backend b { .host = "127.0.0.1"; }
+ sub vcl_bar {
+ }
+ sub vcl_recv {
+ call vcl_bar;
+ }
+}
+
+varnish v1 -errvcl {Names of VCL acl's cannot contain '-'} {
+ backend b { .host = "127.0.0.1"; }
+ acl foo-bar {
+ }
+ sub vcl_recv {
+ if (client.ip ~ foo.bar) {
+ }
+ }
+}
diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c
index eb3bace..fa8a7d7 100644
--- a/lib/libvcl/vcc_acl.c
+++ b/lib/libvcl/vcc_acl.c
@@ -472,6 +472,12 @@ vcc_Acl(struct vcc *tl)
VTAILQ_INIT(&tl->acl);
ExpectErr(tl, ID);
+ if (!vcc_isCid(tl->t)) {
+ VSB_printf(tl->sb,
+ "Names of VCL acl's cannot contain '-'\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
an = tl->t;
vcc_NextToken(tl);
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index f53248b..e6a3f6c 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -171,6 +171,12 @@ parse_new(struct vcc *tl)
vcc_NextToken(tl);
ExpectErr(tl, ID);
+ if (!vcc_isCid(tl->t)) {
+ VSB_printf(tl->sb,
+ "Names of VCL objects cannot contain '-'\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
sy1 = VCC_FindSymbol(tl, tl->t, SYM_NONE);
XXXAZ(sy1);
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index b04236f..c34ffc4 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -133,6 +133,10 @@ IsMethod(const struct token *t)
if (vcc_IdIs(t, m->name))
return (m - method_tab);
}
+ if ((t->b[0] == 'v'|| t->b[0] == 'V') &&
+ (t->b[1] == 'c'|| t->b[1] == 'C') &&
+ (t->b[2] == 'l'|| t->b[2] == 'L'))
+ return (-2);
return (-1);
}
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index fb3a969..64b5995 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -49,10 +49,12 @@
#endif
struct vsb;
+struct token;
#define isident1(c) (isalpha(c))
#define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-')
#define isvar(c) (isident(c) || (c) == '.')
+int vcc_isCid(const struct token *t);
unsigned vcl_fixed_token(const char *p, const char **q);
extern const char * const vcl_tnames[256];
void vcl_output_lang_h(struct vsb *sb);
diff --git a/lib/libvcl/vcc_parse.c b/lib/libvcl/vcc_parse.c
index ff70d64..e334846 100644
--- a/lib/libvcl/vcc_parse.c
+++ b/lib/libvcl/vcc_parse.c
@@ -212,9 +212,23 @@ vcc_Function(struct vcc *tl)
vcc_NextToken(tl);
ExpectErr(tl, ID);
+ if (!vcc_isCid(tl->t)) {
+ VSB_printf(tl->sb,
+ "Names of VCL sub's cannot contain '-'\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
m = IsMethod(tl->t);
- if (m != -1) {
+ if (m == -2) {
+ VSB_printf(tl->sb,
+ "VCL sub's named 'vcl*' are reserved names.\n");
+ vcc_ErrWhere(tl, tl->t);
+ VSB_printf(tl->sb, "Valid vcl_* methods are:\n");
+ for (i = 0; method_tab[i].name != NULL; i++)
+ VSB_printf(tl->sb, "\t%s\n", method_tab[i].name);
+ return;
+ } else if (m != -1) {
assert(m < VCL_MET_MAX);
tl->fb = tl->fm[m];
if (tl->mprocs[m] == NULL) {
diff --git a/lib/libvcl/vcc_token.c b/lib/libvcl/vcc_token.c
index 577b784..6201fea 100644
--- a/lib/libvcl/vcc_token.c
+++ b/lib/libvcl/vcc_token.c
@@ -293,7 +293,7 @@ vcc_IdIs(const struct token *t, const char *p)
* Check that we have a C-identifier
*/
-static int
+int
vcc_isCid(const struct token *t)
{
const char *q;
More information about the varnish-commit
mailing list