From: Amos Jeffries Date: Sat, 29 Jan 2022 05:02:38 +0000 (+0000) Subject: Bug 5192: esi_parser default is incorrect (#968) X-Git-Tag: SQUID_6_0_1~246 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd7a59970089b5c33b094cc2491bfe62cbcfffc7;p=thirdparty%2Fsquid.git 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. --- diff --git a/src/esi/Module.cc b/src/esi/Module.cc index 9c0d016058..f5eeb4f168 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 ed8a375de2..b923b79d6e 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);