Mailing List Archive

[master] 50a59f105 Fail on recursive use of vcl `include`
commit 50a59f1058017d540b0dccfb5bee18a36bf39923
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Mon Jul 13 10:07:23 2020 +0000

Fail on recursive use of vcl `include`

Fixes: #3360

diff --git a/bin/varnishtest/tests/r03360.vtc b/bin/varnishtest/tests/r03360.vtc
new file mode 100644
index 000000000..842988119
--- /dev/null
+++ b/bin/varnishtest/tests/r03360.vtc
@@ -0,0 +1,15 @@
+varnishtest "Test recusive vcl includes"
+
+shell {echo include '"_recurse.vcl";' > ${tmpdir}/_recurse.vcl}
+shell {echo include '"_recurse2.vcl";' > ${tmpdir}/_recurse1.vcl}
+shell {echo include '"_recurse1.vcl";' > ${tmpdir}/_recurse2.vcl}
+
+varnish v1 -arg "-p vcl_path=${tmpdir}" -errvcl "Recursive include of" {
+ backend b { .host = "127.0.0.1"; }
+ include "_recurse.vcl" ;
+}
+
+varnish v2 -arg "-p vcl_path=${tmpdir}" -errvcl "Recursive include of" {
+ backend b { .host = "127.0.0.1"; }
+ include "_recurse1.vcl" ;
+}
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 6bf82bfa0..b181dc67d 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -553,6 +553,7 @@ vcc_resolve_includes(struct vcc *tl)
{
struct token *t, *t1, *t2;
struct source *sp;
+ const struct source *sp1;
struct vsb *vsb;
const char *p;

@@ -607,6 +608,22 @@ vcc_resolve_includes(struct vcc *tl)
vcc_ErrWhere(tl, t1);
return;
}
+
+ for (sp1 = t->src; sp1 != NULL; sp1 = sp1->parent)
+ if (!strcmp(sp1->name, sp->name))
+ break;
+ if (sp1 != NULL) {
+ VSB_printf(tl->sb,
+ "Recursive include of \"%s\"\n\n", sp->name);
+ vcc_ErrWhere(tl, t1);
+ for (sp1 = t->src; sp1 != NULL; sp1 = sp1->parent) {
+ if (sp1->parent_tok)
+ vcc_ErrWhere(tl, sp1->parent_tok);
+ }
+ return;
+ }
+ sp->parent = t->src;
+ sp->parent_tok = t1;
VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++;
tl->t = t2;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 1c9053b24..b6db44343 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -85,6 +85,8 @@ struct source {
const char *e;
unsigned idx;
char *freeit;
+ const struct source *parent;
+ const struct token *parent_tok;
};

struct token {
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit