Commit 7be07e17 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make <![CDATA[...]]> stateful and handle it correctly across

storage boundaries.  Complain if it isn't closed at the end.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2281 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 100f9de5
...@@ -80,6 +80,7 @@ struct esi_work { ...@@ -80,6 +80,7 @@ struct esi_work {
int is_esi; int is_esi;
int remflg; /* inside <esi:remove> </esi:remove> */ int remflg; /* inside <esi:remove> </esi:remove> */
int incmt; /* inside <!--esi ... --> comment */ int incmt; /* inside <!--esi ... --> comment */
int incdata; /* inside <![CCDATA[ ... ]]> */
}; };
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -356,15 +357,33 @@ esi_parse2(struct esi_work *ew) ...@@ -356,15 +357,33 @@ esi_parse2(struct esi_work *ew)
ew->o.b = t.b; ew->o.b = t.b;
ew->o.e = t.b; ew->o.e = t.b;
for (p = t.b; p < t.e; ) { for (p = t.b; p < t.e; ) {
assert(p >= t.b);
assert(p < t.e);
if (ew->incdata) {
/*
* We are inside an <![CDATA[ constuct and mus skip
* to the end marker ]]>.
*/
if (*p != ']') {
p++;
} else {
if (p + 2 >= t.e)
return (p);
if (!memcmp(p, "]]>", 3)) {
ew->incdata = 0;
p += 3;
} else
p++;
}
continue;
}
if (ew->incmt && *p == '-') { if (ew->incmt && *p == '-') {
/* /*
* We are inside an <!--esi comment and need to zap * We are inside an <!--esi comment and need to zap
* the end comment marker --> when we see it. * the end comment marker --> when we see it.
*/ */
if (p + 2 >= t.e) { if (p + 2 >= t.e)
/* XXX: need to return pending ew->incmt */
return (p); return (p);
}
if (!memcmp(p, "-->", 3)) { if (!memcmp(p, "-->", 3)) {
ew->incmt = 0; ew->incmt = 0;
ew->o.e = p; ew->o.e = p;
...@@ -425,18 +444,12 @@ esi_parse2(struct esi_work *ew) ...@@ -425,18 +444,12 @@ esi_parse2(struct esi_work *ew)
if (!memcmp(p, "<![CDATA[", i > 9 ? 9 : i)) { if (!memcmp(p, "<![CDATA[", i > 9 ? 9 : i)) {
/* /*
* cdata <![CDATA[...]]> at least 12 char * cdata <![CDATA[ at least 9 char
* XXX: can span multiple chunks
*/ */
if (i < 12) if (i < 9)
return (p); return (p);
for (q = p + 9; ; q++) { ew->incdata = 1;
if (q + 2 >= t.e) p += 9;
return (p);
if (!memcmp(q, "]]>", 3))
break;
}
p = q + 3;
continue; continue;
} }
...@@ -683,6 +696,9 @@ VRT_ESI(struct sess *sp) ...@@ -683,6 +696,9 @@ VRT_ESI(struct sess *sp)
/* 'p' is cached starting point for next storage part */ /* 'p' is cached starting point for next storage part */
} }
if (ew->incdata)
esi_error(ew, ew->t.e, -1,
"ESI 1.0 unterminated <![CDATA[ element");
if (ew->remflg) if (ew->remflg)
esi_error(ew, ew->t.e, -1, esi_error(ew, ew->t.e, -1,
"ESI 1.0 unterminated <esi:remove> element"); "ESI 1.0 unterminated <esi:remove> element");
......
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