]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 5192: esi_parser default is incorrect (#968)
authorAmos Jeffries <yadij@users.noreply.github.com>
Sat, 29 Jan 2022 05:02:38 +0000 (05:02 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Fri, 1 Apr 2022 06:49:22 +0000 (19:49 +1300)
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
src/esi/Parser.cc

index 03b727ec1e1a17f1cc8c2f634d10e8431089ef61..ef943e4772e187c69eaebbe8ea187787b248f855 100644 (file)
@@ -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);
index 07d9ab9f821174fe1704821f84f11337f7571c00..773827e4494aa9f2c2c80782741f7eea79cff652 100644 (file)
@@ -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);