Commit 50a59f10 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fail on recursive use of vcl `include`

Fixes:	#3360
parent 7bb73c58
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" ;
}
......@@ -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;
......
......@@ -85,6 +85,8 @@ struct source {
const char *e;
unsigned idx;
char *freeit;
const struct source *parent;
const struct token *parent_tok;
};
struct token {
......
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