]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Snort2Lua: clearing badbit before using seekg(). Fixing frag3_engine bug
authorJosh <jrosenba@cisco.com>
Mon, 10 Nov 2014 20:22:32 +0000 (14:22 -0600)
committerJosh <jrosenba@cisco.com>
Mon, 10 Nov 2014 20:22:32 +0000 (14:22 -0600)
tools/snort2lua/keyword_states/kws_rule.cc
tools/snort2lua/preprocessor_states/pps_frag3_engine.cc
tools/snort2lua/preprocessor_states/pps_normalizers.cc
tools/snort2lua/rule_states/rule_base64_decode.cc
tools/snort2lua/rule_states/rule_content.cc
tools/snort2lua/rule_states/rule_file_data.cc
tools/snort2lua/rule_states/rule_react.cc
tools/snort2lua/rule_states/rule_threshold.cc
tools/snort2lua/utils/s2l_util.cc

index 73b6c7f1b5a8d55e9a3a66554648d396b12dfac3..35c5108418bf30db44768cc50cab0bcc02e228e5 100644 (file)
@@ -61,7 +61,7 @@ bool RuleHeader::convert(std::istringstream& data_stream)
 
     // Now, remove the last ')' and anything beyond. We will automatically
     // add that part back when printing each rule.
-    std::streamoff curr_pos = data_stream.tellg();
+    const std::istringstream::off_type curr_pos = data_stream.tellg();
     std::string rule_string = data_stream.str();
     std::size_t end_pos = rule_string.rfind(')');
     rule_string = rule_string.substr(0, end_pos);
index b77ef369cfc82372691d10c56898a2d200cf5f1a..b15a5f0b356f00518930df7b60627606ed04c695 100644 (file)
@@ -48,21 +48,21 @@ private:
 std::string Frag3Engine::choose_table_name(std::istringstream& data_stream)
 {
     static uint32_t binding_id = 0;
-    const std::streamoff pos = data_stream.tellg();
+    const std::istringstream::off_type pos = data_stream.tellg();
     std::string keyword;
 
     while (data_stream >> keyword)
     {
         if (!keyword.compare("bind_to"))
         {
-            data_stream.seekg(pos);
             data_stream.clear();
+            data_stream.seekg(pos);
             return "stream_ip_" + std::to_string(binding_id++);
         }
     }
 
-    data_stream.seekg(pos);
     data_stream.clear();
+    data_stream.seekg(pos);
     return "stream_ip";
 }
 
index c58df4e420ac39b9c47f107ca5d11546a3921aa6..8f8581e54ab7258542616736746f420d20dc9936 100644 (file)
@@ -293,6 +293,7 @@ bool TcpNormalizer::convert(std::istringstream& data_stream)
 
                 else
                 {
+                    data_stream.clear();
                     data_stream.seekg(pos);
                     break;
                 }
index 92dcfe7cfe6d9b0e0a79c3a226c527323921f361..5716ed0c92e3044b28a02f0d6b305ac8ab921e08 100644 (file)
@@ -59,6 +59,7 @@ bool Base64Decode::convert(std::istringstream& data_stream)
         if (args.find(":") != std::string::npos)
         {
             rule_api.add_option("base64_decode");
+            data_stream.clear();
             data_stream.seekg(pos);
         }
         else
@@ -76,6 +77,7 @@ bool Base64Decode::convert(std::istringstream& data_stream)
             }
             else
             {
+                data_stream.clear();
                 data_stream.seekg(pos);
                 rule_api.add_option("base64_decode");
             }
index 3d65ae2aec20ddde845ba5da82ad24c3ba9bfb10..95d262132b57f0c01d6818ef1325289713bce671 100644 (file)
@@ -237,8 +237,8 @@ bool Content<option_name>::convert(std::istringstream& data_stream)
 
             // since this option is not an content modifier,
             // lets coninue parsing the rest of the rule.
-            data_stream.seekg(pos);
             data_stream.clear();
+            data_stream.seekg(pos);
             return set_next_rule_state(data_stream);
         }
 
index 57e62ee9c2272d8bb2c411ea31fa301ca7eeb9b2..e88b5b727536fae382e41f93d0b70ab2148153b2 100644 (file)
@@ -59,6 +59,7 @@ bool FileData::convert(std::istringstream& data_stream)
         // Therefore, if a colon is present, we are in the next rule option.
         if (args.find(":") != std::string::npos)
         {
+            data_stream.clear();
             data_stream.seekg(pos);
         }
         else
@@ -68,9 +69,14 @@ bool FileData::convert(std::istringstream& data_stream)
             std::istringstream(args) >> tmp;
 
             if (!tmp.compare("mime"))
+            {
                 rule_api.add_comment("file_data's 'mime' option has been deleted");
+            }
             else
+            {
+                data_stream.clear();
                 data_stream.seekg(pos);
+            }
         }
     }
     return set_next_rule_state(data_stream);
index d6688675905adce248aa7347cde163ea3ce23abd..5ff50882c86f15a807abb9edfc5e5fc70099c3b9 100644 (file)
@@ -46,7 +46,7 @@ bool React::convert(std::istringstream& data_stream)
 {
     std::string args;
     std::string tmp;
-    std::streamoff pos = data_stream.tellg();
+    std::istringstream::off_type pos = data_stream.tellg();
 
     args = util::get_rule_option_args(data_stream);
 
@@ -58,6 +58,7 @@ bool React::convert(std::istringstream& data_stream)
         // Therefore, if a colon is present, we are in the next rule option.
         if (args.find(":") != std::string::npos)
         {
+            data_stream.clear();
             data_stream.seekg(pos);
         }
         else
@@ -120,6 +121,7 @@ bool React::convert(std::istringstream& data_stream)
             }
             else
             {
+                data_stream.clear();
                 data_stream.seekg(pos);
             }
 
index be8ab940f7d4760562ea2c395b1e07c5097f1afc..9a8ae501e5adc2c0439ebec4223019473a15f5e5 100644 (file)
@@ -82,7 +82,7 @@ bool Threshold::convert(std::istringstream& data_stream)
     }
 
     // save the current position
-    const std::streamoff curr_pos = data_stream.tellg();
+    const std::istringstream::off_type curr_pos = data_stream.tellg();
 
     if (curr_pos == -1)
         data_stream.clear();
index 7597751b099c79c363d5bf777040ebee927f3b1e..7a84bc9e1efc11e288f76c3a6b137e85ae046515 100644 (file)
@@ -243,8 +243,8 @@ std::string rule_option_find_val(std::istringstream& data_stream,
         {
             // found an option without a colon, so set stream
             // to semi-colon
-            std::streamoff off = 1 + (std::streamoff)(tmp_pos) +
-                                 (std::streamoff)(semi_colon_pos);
+            std::istringstream::off_type off = 1 +
+                (std::streamoff)(tmp_pos) + (std::streamoff)(semi_colon_pos);
             data_stream.seekg(off);
             rule_keyword = rule_keyword.substr(0, semi_colon_pos);
         }