<p dir="ltr">Isn't dash (-) usage quite widespread?</p>
<p dir="ltr">I'd expect it to be the most common character outside digits and numbers.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On 8 Sep 2016 12:21 pm, "Poul-Henning Kamp" <<a href="mailto:phk@freebsd.org">phk@freebsd.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
commit 169e162c7506614090a33faef7a0df<wbr>38c6ffac7a<br>
Author: Poul-Henning Kamp <phk@FreeBSD.org><br>
Date: Thu Sep 8 11:19:39 2016 +0000<br>
<br>
Enforce that VCL names must be C-language identifiers ([A-Za-z][A-Za-z0-9_]*)<br>
<br>
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c<br>
index 3fb2132..56c89b7 100644<br>
--- a/bin/varnishd/mgt/mgt_vcl.c<br>
+++ b/bin/varnishd/mgt/mgt_vcl.c<br>
@@ -42,6 +42,7 @@<br>
<br>
#include "libvcc.h"<br>
#include "vcli_serve.h"<br>
+#include "vct.h"<br>
#include "vev.h"<br>
#include "vtim.h"<br>
<br>
@@ -81,6 +82,74 @@ static struct vev *e_poker;<br>
<br>
/*----------------------------<wbr>------------------------------<wbr>----------*/<br>
<br>
+static struct vclprog *<br>
+mcf_vcl_byname(const char *name)<br>
+{<br>
+ struct vclprog *vp;<br>
+<br>
+ VTAILQ_FOREACH(vp, &vclhead, list)<br>
+ if (!strcmp(name, vp->name))<br>
+ return (vp);<br>
+ return (NULL);<br>
+}<br>
+<br>
+static int<br>
+mcf_bad_vclname(struct cli *cli, const char *name)<br>
+{<br>
+ const char *p;<br>
+ int bad = 0;<br>
+<br>
+ AN(name);<br>
+ p = name;<br>
+ if (!vct_isalpha(*p))<br>
+ bad = *p;<br>
+ for (p++; bad == 0 && *p != '\0'; p++)<br>
+ if (!vct_isalpha(*p) && !vct_isdigit(*p) && *p != '_')<br>
+ bad = *p;<br>
+ if (bad) {<br>
+ VCLI_SetResult(cli, CLIS_PARAM);<br>
+ VCLI_Out(cli, "Illegal character in VCL name ");<br>
+ if (bad > 0x20 && bad < 0x7f)<br>
+ VCLI_Out(cli, "('%c')", bad);<br>
+ else<br>
+ VCLI_Out(cli, "(0x%02x)", bad & 0xff);<br>
+ }<br>
+ return (bad);<br>
+}<br>
+<br>
+static struct vclprog *<br>
+mcf_find_vcl(struct cli *cli, const char *name)<br>
+{<br>
+ struct vclprog *vp;<br>
+<br>
+ if (mcf_bad_vclname(cli, name))<br>
+ return (NULL);<br>
+<br>
+ vp = mcf_vcl_byname(name);<br>
+ if (vp == NULL) {<br>
+ VCLI_SetResult(cli, CLIS_PARAM);<br>
+ VCLI_Out(cli, "No VCL named %s known.", name);<br>
+ }<br>
+ return (vp);<br>
+}<br>
+<br>
+static int<br>
+mcf_find_no_vcl(struct cli *cli, const char *name)<br>
+{<br>
+<br>
+ if (mcf_bad_vclname(cli, name))<br>
+ return (0);<br>
+<br>
+ if (mcf_vcl_byname(name) != NULL) {<br>
+ VCLI_SetResult(cli, CLIS_PARAM);<br>
+ VCLI_Out(cli, "Already a VCL named %s", name);<br>
+ return (0);<br>
+ }<br>
+ return (1);<br>
+}<br>
+<br>
+/*---------------------------<wbr>------------------------------<wbr>-----------*/<br>
+<br>
static void<br>
mgt_vcl_dep_add(struct vclprog *vp_from, struct vclprog *vp_to)<br>
{<br>
@@ -163,17 +232,6 @@ mgt_vcl_del(struct vclprog *vp)<br>
FREE_OBJ(vp);<br>
}<br>
<br>
-static struct vclprog *<br>
-mgt_vcl_byname(const char *name)<br>
-{<br>
- struct vclprog *vp;<br>
-<br>
- VTAILQ_FOREACH(vp, &vclhead, list)<br>
- if (!strcmp(name, vp->name))<br>
- return (vp);<br>
- return (NULL);<br>
-}<br>
-<br>
void<br>
mgt_vcl_depends(struct vclprog *vp1, const char *name)<br>
{<br>
@@ -181,7 +239,7 @@ mgt_vcl_depends(struct vclprog *vp1, const char *name)<br>
<br>
CHECK_OBJ_NOTNULL(vp1, VCLPROG_MAGIC);<br>
<br>
- vp2 = mgt_vcl_byname(name);<br>
+ vp2 = mcf_vcl_byname(name);<br>
CHECK_OBJ_NOTNULL(vp2, VCLPROG_MAGIC);<br>
mgt_vcl_dep_add(vp1, vp2);<br>
}<br>
@@ -390,16 +448,11 @@ mgt_push_vcls_and_start(struct cli *cli, unsigned *status, char **p)<br>
static void __match_proto__(cli_func_t)<br>
mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv)<br>
{<br>
- struct vclprog *vp;<br>
<br>
(void)priv;<br>
<br>
- vp = mgt_vcl_byname(av[2]);<br>
- if (vp != NULL) {<br>
- VCLI_Out(cli, "Already a VCL program named %s", av[2]);<br>
- VCLI_SetResult(cli, CLIS_PARAM);<br>
+ if (!mcf_find_no_vcl(cli, av[2]))<br>
return;<br>
- }<br>
<br>
mgt_new_vcl(cli, av[2], av[3], "<vcl.inline>", av[4], 0);<br>
}<br>
@@ -407,31 +460,14 @@ mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv)<br>
static void __match_proto__(cli_func_t)<br>
mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)<br>
{<br>
- struct vclprog *vp;<br>
<br>
(void)priv;<br>
- vp = mgt_vcl_byname(av[2]);<br>
- if (vp != NULL) {<br>
- VCLI_Out(cli, "Already a VCL program named %s", av[2]);<br>
- VCLI_SetResult(cli, CLIS_PARAM);<br>
+ if (!mcf_find_no_vcl(cli, av[2]))<br>
return;<br>
- }<br>
<br>
mgt_new_vcl(cli, av[2], NULL, av[3], av[4], 0);<br>
}<br>
<br>
-static struct vclprog *<br>
-mcf_find_vcl(struct cli *cli, const char *name)<br>
-{<br>
- struct vclprog *vp;<br>
-<br>
- vp = mgt_vcl_byname(name);<br>
- if (vp == NULL) {<br>
- VCLI_SetResult(cli, CLIS_PARAM);<br>
- VCLI_Out(cli, "No configuration named %s known.", name);<br>
- }<br>
- return (vp);<br>
-}<br>
<br>
static void __match_proto__(cli_func_t)<br>
mcf_vcl_state(struct cli *cli, const char * const *av, void *priv)<br>
@@ -614,6 +650,10 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)<br>
int i;<br>
<br>
(void)priv;<br>
+ if (mcf_bad_vclname(cli, av[2]))<br>
+ return;<br>
+ if (mcf_bad_vclname(cli, av[3]))<br>
+ return;<br>
vpt = mcf_find_vcl(cli, av[3]);<br>
if (vpt == NULL)<br>
return;<br>
@@ -628,7 +668,7 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)<br>
vpt->label->name);<br>
return;<br>
}<br>
- vpl = mgt_vcl_byname(av[2]);<br>
+ vpl = mcf_vcl_byname(av[2]);<br>
if (vpl != NULL) {<br>
if (strcmp(vpl->state, VCL_STATE_LABEL)) {<br>
VCLI_SetResult(cli, CLIS_PARAM);<br>
@@ -643,12 +683,6 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)<br>
mgt_vcl_dep_del(VTAILQ_FIRST(&<wbr>vpl->dfrom));<br>
AN(VTAILQ_EMPTY(&vpl->dfrom));<br>
} else {<br>
- /* XXX should check for C-syntax */<br>
- if (strchr(av[2], '.')) {<br>
- VCLI_SetResult(cli, CLIS_PARAM);<br>
- VCLI_Out(cli, "VCL labels cannot contain '.'");<br>
- return;<br>
- }<br>
vpl = mgt_vcl_add(av[2], VCL_STATE_LABEL);<br>
}<br>
AN(vpl);<br>
diff --git a/bin/varnishtest/tests/<wbr>v00048.vtc b/bin/varnishtest/tests/<wbr>v00048.vtc<br>
index bef46c1..35ba584 100644<br>
--- a/bin/varnishtest/tests/<wbr>v00048.vtc<br>
+++ b/bin/varnishtest/tests/<wbr>v00048.vtc<br>
@@ -7,6 +7,11 @@ server s1 {<br>
<br>
varnish v1 -vcl+backend {}<br>
<br>
+# VCL name must be C-names<br>
+varnish v1 -clierr 106 {vcl.inline 0000 "vcl 4.0; backend b { .host = \"localhost\";} "}<br>
+varnish v1 -clierr 106 {vcl.inline a00/ "vcl 4.0; backend b { .host = \"localhost\";} "}<br>
+varnish v1 -clierr 106 {vcl.inline a00å "vcl 4.0; backend b { .host = \"localhost\";} "}<br>
+<br>
varnish v1 -vcl+backend {<br>
sub vcl_recv {<br>
return (synth(400));<br>
<br>
______________________________<wbr>_________________<br>
varnish-commit mailing list<br>
<a href="mailto:varnish-commit@varnish-cache.org">varnish-commit@varnish-cache.<wbr>org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit" rel="noreferrer" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/<wbr>varnish-commit</a></blockquote></div></div>