From 6bc9f8d6298b6254d4daf52c8e927fe79ce22b3c Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 24 Jul 2008 20:39:04 +0000 Subject: [PATCH] Add a check to avoid doing ESI parsing of objects that do not look like XML. Our definition of "looks like XML" is that the first non-white-space character is '<'. Add a new parameter "esi_syntax" with bits to steer the ESI parser. Use the first bit to disable the "looks like XML" check. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3016 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_vrt_esi.c | 20 ++++++++++++++++++++ varnish-cache/bin/varnishd/heritage.h | 3 +++ varnish-cache/bin/varnishd/mgt_param.c | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache_vrt_esi.c b/varnish-cache/bin/varnishd/cache_vrt_esi.c index 315bd394..e5da1fc5 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_esi.c +++ b/varnish-cache/bin/varnishd/cache_vrt_esi.c @@ -637,6 +637,26 @@ VRT_ESI(struct sess *sp) CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + if (!(params->esi_syntax & 0x00000001)) { + /* + * By default, we will not ESI process an object where + * the first non-space character is different from '<' + */ + st = VTAILQ_FIRST(&sp->obj->store); + AN(st); + for (u = 0; u < st->len; u++) { + if (isspace(st->ptr[u])) + continue; + if (st->ptr[u] == '<') + break; + WSP(sp, SLT_ESI_xmlerror, + "No ESI processing, " + "binary object: 0x%02x at pos %u.", + st->ptr[u], u); + return; + } + } + /* XXX: only if GET ? */ ew = eww; memset(eww, 0, sizeof eww); diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 767ac8c7..e98920cf 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -143,6 +143,9 @@ struct params { /* Maximum esi:include depth allowed */ unsigned max_esi_includes; + /* ESI parser hints */ + unsigned esi_syntax; + /* Rush exponent */ unsigned rush_exponent; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index d1f29e84..f0bd5323 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -719,6 +719,13 @@ static const struct parspec parspec[] = { "the backend, so don't increase thoughtlessly.\n", 0, "4", "restarts" }, + { "esi_syntax", + tweak_uint, &master.esi_syntax, 0, UINT_MAX, + "Bitmap controlling ESI parsing code:\n" + " 0x00000001 - Don't check if it looks like XML\n" + "Use 0x notation and do the bitor in your head :-)\n", + 0, + "0", "restarts" }, { "max_esi_includes", tweak_uint, &master.max_esi_includes, 0, UINT_MAX, "Maximum depth of esi:include processing." -- 2.39.5