------------------------------------------------------------ revno: 13672 revision-id: squid3@treenet.co.nz-20141208081125-bb6amoj08trqgxul parent: squid3@treenet.co.nz-20141203114356-3ah5egxm478w0rdv fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4135 committer: Amos Jeffries branch nick: 3.5 timestamp: Mon 2014-12-08 00:11:25 -0800 message: Bug 4135: Support \-escaped character in regex patterns 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. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20141208081125-bb6amoj08trqgxul # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 1160254395b80cfea39c42d4462559c82e8e688b # timestamp: 2014-12-08 08:50:56 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20141203114356-\ # 3ah5egxm478w0rdv # # Begin patch === modified file 'doc/release-notes/release-3.5.sgml' --- doc/release-notes/release-3.5.sgml 2014-10-31 09:15:45 +0000 +++ doc/release-notes/release-3.5.sgml 2014-12-08 08:11:25 +0000 @@ -401,6 +401,12 @@ more circumstances than squid-2 idle connections were. They are also spread over all IPs of the peer. + configuration_includes_quoted_values +

Regex pattern values cannot be parsed in parts of squid.conf when this + directive is configured to ON. Instead of quoted strings Squid + now accepts regex \-escaped characters (including escaped spaces) in all + regex patterns. + external_acl_type

New format code %ssl::>sni to send SSL client SNI.

New format code %ssl::<cert_subject to send SSL server certificate DN. === modified file 'src/ConfigParser.cc' --- src/ConfigParser.cc 2014-11-21 09:27:22 +0000 +++ src/ConfigParser.cc 2014-12-08 08:11:25 +0000 @@ -23,6 +23,7 @@ std::queue 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]"; @@ -261,12 +262,25 @@ const char *sep; if (ConfigParser::ParseQuotedOrToEol_) sep = "\n"; + else if (ConfigParser::RecognizeQuotedPair_) + sep = w_space "\\"; else if (!ConfigParser::RecognizeQuotedValues || *nextToken == '(') sep = w_space; else sep = w_space "("; nextToken += strcspn(nextToken, sep); + while (ConfigParser::RecognizeQuotedPair_ && *nextToken == '\\') { + // NP: do not permit \0 terminator to be escaped. + if (*(nextToken+1) && *(nextToken+1) != '\r' && *(nextToken+1) != '\n') { + nextToken += 2; // skip the quoted-pair (\-escaped) character + nextToken += strcspn(nextToken, sep); + } else { + debugs(3, DBG_CRITICAL, "FATAL: Unescaped '\' character in regex pattern: " << tokenStart); + self_destruct(); + } + } + if (ConfigParser::RecognizeQuotedValues && *nextToken == '(') { if (strncmp(tokenStart, "parameters", nextToken - tokenStart) == 0) type = ConfigParser::FunctionParameters; @@ -432,7 +446,9 @@ 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 +459,9 @@ 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; } === modified file 'src/ConfigParser.h' --- src/ConfigParser.h 2014-09-13 13:59:43 +0000 +++ src/ConfigParser.h 2014-12-08 08:11:25 +0000 @@ -201,6 +201,7 @@ static std::queue 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. };