From 24b41a0dbc916b69ff7948e08960f721ddf242b4 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 29 Jan 2022 05:02:38 +0000 Subject: [PATCH] Bug 5192: esi_parser default is incorrect (#968) Since commit f5f7786 reversed the internal list order of ESI parser registry, the esi_parser documentation and code comment in esi/Module.cc have been incorrect. Return ESI parsers to the documented default behaviour and make that default explicit in the code selecting which Parser to initialize. Also fixed an inverted test that resulted in the esi_parser configured library _not_ to be the one used. --- src/esi/Module.cc | 2 -- src/esi/Parser.cc | 31 ++++++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/esi/Module.cc b/src/esi/Module.cc index 03b727ec1e..ef943e4772 100644 --- a/src/esi/Module.cc +++ b/src/esi/Module.cc @@ -22,8 +22,6 @@ static ESIParser::Register *prExpat = 0; void Esi::Init() { - // register in reverse order of preference. - // The latest registered parser will be used as default. #if HAVE_LIBEXPAT assert(!prExpat); // we should be called once prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser); diff --git a/src/esi/Parser.cc b/src/esi/Parser.cc index 07d9ab9f82..773827e449 100644 --- a/src/esi/Parser.cc +++ b/src/esi/Parser.cc @@ -9,6 +9,7 @@ /* DEBUG: section 86 ESI processing */ #include "squid.h" +#include "Debug.h" #include "esi/Parser.h" #include "fatal.h" @@ -25,19 +26,27 @@ ESIParser::GetRegistry() ESIParser::Pointer ESIParser::NewParser(ESIParserClient *aClient) { - if (Parser == NULL) { - Parser = GetRegistry().front(); - - // if type name matters, use it - if (strcasecmp(Type, "auto") != 0) { - for (auto *p : GetRegistry()) { - if (p && strcasecmp(p->name, Type) != 0) - Parser = p; - } + if (!Parser) { + // if esi_parser is configured, use that + const char *selectParserName = Type; + if (!selectParserName || strcasecmp(selectParserName, "auto") == 0) { +#if HAVE_LIBXML2 + // libxml2 is the more secure. prefer when possible + selectParserName = "libxml2"; +#else + // expat is more widely available + selectParserName = "expat"; +#endif } - if (Parser == NULL) - fatal ("Unknown ESI Parser type"); + for (auto *p : GetRegistry()) { + if (p && strcasecmp(p->name, selectParserName) == 0) + Parser = p; + } + + if (!Parser) + fatalf("Unknown ESI Parser type '%s'", selectParserName); + debugs(86, 2, "selected ESI parser: " << Parser->name); } return (Parser->newParser)(aClient); -- 2.47.2