Skip to content

Commit

Permalink
Fail on recursive use of vcl include
Browse files Browse the repository at this point in the history
Fixes:	#3360
  • Loading branch information
bsdphk committed Jul 13, 2020
1 parent 7bb73c5 commit 50a59f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 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" ;
}
17 changes: 17 additions & 0 deletions lib/libvcc/vcc_compile.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/libvcc/vcc_compile.h
Expand Up @@ -85,6 +85,8 @@ struct source {
const char *e;
unsigned idx;
char *freeit;
const struct source *parent;
const struct token *parent_tok;
};

struct token {
Expand Down

0 comments on commit 50a59f1

Please sign in to comment.