From: Bhagya Tholpady (bbantwal) Date: Fri, 18 Dec 2020 15:11:47 +0000 (+0000) Subject: Merge pull request #2672 in SNORT/snort3 from ~OSERHIIE/snort3:bug_CSCvw81752 to... X-Git-Tag: 3.0.3-6~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aa7d59122752e3ab435af4679e5409ca8eb966f;p=thirdparty%2Fsnort3.git Merge pull request #2672 in SNORT/snort3 from ~OSERHIIE/snort3:bug_CSCvw81752 to master Squashed commit of the following: commit 396f8663f2fb7cc95a318675dc0f961abf1ca2d6 Author: Oleksandr Serhiienko Date: Wed Dec 16 13:52:00 2020 +0200 parser: fix escape logic for --dump-rule-meta output --- diff --git a/src/parser/parse_rule.cc b/src/parser/parse_rule.cc index 93dd904f6..b769eda01 100644 --- a/src/parser/parse_rule.cc +++ b/src/parser/parse_rule.cc @@ -1082,12 +1082,24 @@ static bool is_already_escaped(const std::string& opt_key) static std::string escape(const std::string& s) { std::string res; + int quotes_first = 0; + int quotes_last = std::count(s.begin(), s.end(), '"') - 1; + int quotes_count = quotes_first; for ( auto it = s.begin(); it != s.end(); ++it ) { switch ( *it ) { - case '"': res += ( it > s.begin() and it < s.end() - 1 ) ? "\\\"" : "\""; continue; + case '"': + { + if ( ( quotes_count > quotes_first ) and ( quotes_count < quotes_last ) ) + res += "\\\""; + else + res += "\""; + + ++quotes_count; + continue; + } case '\\': res += "\\\\"; continue; case '\a': res += "\\a"; continue; case '\b': res += "\\b"; continue;