]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4135: Support \-escaped character in regex patterns
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 3 Dec 2014 14:12:12 +0000 (06:12 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 3 Dec 2014 14:12:12 +0000 (06:12 -0800)
Squid cannot parse regex patterns as quoted strings since the pattern may
itself contain quote characters as part of the syntax.

Since we updated the squid.conf ConfigParser it is now possible to
handle regex patterns containing quoted-pair (\-escaped) characters
properly.

Add support for escaping by detecting the '\' characters as token
delimiters, and explicitly skipping the following character regardless
of whether it is a SP or not.

Escape detection is only added during parsing of regex tokens or
files listing regex patterns.

doc/release-notes/release-3.5.sgml
src/ConfigParser.cc
src/ConfigParser.h

index 060d33db0b97baf0a485d3802440c3703c5d54c6..f6da195b6b48d367c7fab5b8a16b5b8428cac55b 100644 (file)
@@ -403,6 +403,12 @@ This section gives a thorough account of those changes in three categories:
           more circumstances than squid-2 idle connections were. They are
           also spread over all IPs of the peer.
 
+       <tag>configuration_includes_quoted_values</tag>
+       <p>Regex pattern values cannot be parsed in parts of squid.conf when this
+          directive is configured to <em>ON</em>. Instead of quoted strings Squid
+          now accepts regex \-escaped characters (including escaped spaces) in all
+          regex patterns.
+
        <tag>external_acl_type</tag>
        <p>New format code <em>%ssl::&gt;sni</em> to send SSL client SNI.
        <p>New format code <em>%ssl::&lt;cert_subject</em> to send SSL server certificate DN.
index e92e8d9686f549af6322146c57fdd4adea20b7f6..9080d86feb5df948f67cca9b888f07ebb6e31183 100644 (file)
@@ -23,6 +23,7 @@ std::queue<char *> ConfigParser::CfgLineTokens_;
 std::queue<std::string> ConfigParser::Undo_;
 bool ConfigParser::AllowMacros_ = false;
 bool ConfigParser::ParseQuotedOrToEol_ = false;
+bool ConfigParser::RecognizeQuotedPair_ = false;
 bool ConfigParser::PreviewMode_ = false;
 
 static const char *SQUID_ERROR_TOKEN = "[invalid token]";
@@ -263,10 +264,18 @@ ConfigParser::TokenParse(const char * &nextToken, ConfigParser::TokenType &type)
         sep = "\n";
     else if (!ConfigParser::RecognizeQuotedValues || *nextToken == '(')
         sep = w_space;
+    else if (ConfigParser::RecognizeQuotedPair_)
+        sep = w_space "\\";
     else
         sep = w_space "(";
     nextToken += strcspn(nextToken, sep);
 
+    // NP: do not permit \0 terminator to be escaped.
+    while (ConfigParser::RecognizeQuotedPair_ && *nextToken && *(nextToken-1) == '\\') {
+        ++nextToken; // skip the quoted-pair (\-escaped) character
+        nextToken += strcspn(nextToken, sep);
+    }
+
     if (ConfigParser::RecognizeQuotedValues && *nextToken == '(') {
         if (strncmp(tokenStart, "parameters", nextToken - tokenStart) == 0)
             type = ConfigParser::FunctionParameters;
@@ -432,7 +441,9 @@ ConfigParser::RegexStrtokFile()
         debugs(3, DBG_CRITICAL, "FATAL: Can not read regex expression while configuration_includes_quoted_values is enabled");
         self_destruct();
     }
+    ConfigParser::RecognizeQuotedPair_ = true;
     char * token = strtokFile();
+    ConfigParser::RecognizeQuotedPair_ = false;
     return token;
 }
 
@@ -443,8 +454,9 @@ ConfigParser::RegexPattern()
         debugs(3, DBG_CRITICAL, "FATAL: Can not read regex expression while configuration_includes_quoted_values is enabled");
         self_destruct();
     }
-
+    ConfigParser::RecognizeQuotedPair_ = true;
     char * token = NextToken();
+    ConfigParser::RecognizeQuotedPair_ = false;
     return token;
 }
 
index 5d536e30cbd41feda7c6f0e46c0c6afced783fa1..465edc6e7e8957dc2cc0df7678183c7f32934a25 100644 (file)
@@ -201,6 +201,7 @@ protected:
     static std::queue<std::string> Undo_; ///< The list with TokenPutBack() queued elements
     static bool AllowMacros_;
     static bool ParseQuotedOrToEol_; ///< The next tokens will be handled as quoted or to_eol token
+    static bool RecognizeQuotedPair_; ///< The next tokens may contain quoted-pair (\-escaped) characters
     static bool PreviewMode_; ///< The next token will not poped from cfg files, will just previewd.
 };