]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2672 in SNORT/snort3 from ~OSERHIIE/snort3:bug_CSCvw81752 to...
authorBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Fri, 18 Dec 2020 15:11:47 +0000 (15:11 +0000)
committerBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Fri, 18 Dec 2020 15:11:47 +0000 (15:11 +0000)
Squashed commit of the following:

commit 396f8663f2fb7cc95a318675dc0f961abf1ca2d6
Author: Oleksandr Serhiienko <oserhiie@cisco.com>
Date:   Wed Dec 16 13:52:00 2020 +0200

    parser: fix escape logic for --dump-rule-meta output

src/parser/parse_rule.cc

index 93dd904f67152b92cc1bc3b776a9d558f07ea8d0..b769eda01fc1a436ad3b4076bb369bf081c6301a 100644 (file)
@@ -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;