]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4531: bufferlen: reset "relative" flag in module::begin method
authorYehor Velykozhon -X (yvelykoz - SOFTSERVE INC at Cisco) <yvelykoz@cisco.com>
Mon, 2 Dec 2024 10:07:29 +0000 (10:07 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Mon, 2 Dec 2024 10:07:29 +0000 (10:07 +0000)
Merge in SNORT/snort3 from ~YVELYKOZ/snort3:bufferlen_reinit to master

Squashed commit of the following:

commit f86e73e67019cc5d99758284b68ebf89ce5b8182
Author: Yehor Velykozhon <yvelykoz@cisco.com>
Date:   Wed Nov 27 12:48:19 2024 +0200

    bufferlen: reset "relative" flag in module::begin method

commit 256ee2c838d7b44f77e7afaee64a12b86f5ad43f
Author: Yehor Velykozhon <yvelykoz@cisco.com>
Date:   Wed Nov 27 14:35:52 2024 +0200

    ips_options: update module::begin and other in several ips options

src/ips_options/ips_bufferlen.cc
src/ips_options/ips_content.cc
src/ips_options/ips_flowbits.cc
src/ips_options/ips_hash.cc
src/ips_options/ips_regex.cc
src/ips_options/ips_sd_pattern.cc

index fbfbcd84a68fa4a0ec5e9723416063d6712a6e0f..c408bb83493b559917f0b35baab6ff5c2fb4d2ff 100644 (file)
@@ -40,7 +40,7 @@ static THREAD_LOCAL ProfileStats lenCheckPerfStats;
 class LenOption : public IpsOption
 {
 public:
-    LenOption(const RangeCheck& c, bool r) : IpsOption(s_name), config(c), relative(r)
+    LenOption(const RangeCheck& c, bool r) : IpsOption(s_name), range(c), relative(r)
     { }
 
     uint32_t hash() const override;
@@ -55,7 +55,7 @@ public:
     { return CAT_READ; }
 
 private:
-    RangeCheck config;
+    RangeCheck range;
     bool relative;
 };
 
@@ -65,9 +65,9 @@ private:
 
 uint32_t LenOption::hash() const
 {
-    uint32_t a = config.hash();
+    uint32_t a = range.hash();
     uint32_t b = IpsOption::hash();
-    uint32_t c = 0;
+    uint32_t c = relative ? 1 : 0;
 
     mix(a,b,c);
     finalize(a,b,c);
@@ -80,7 +80,7 @@ bool LenOption::operator==(const IpsOption& ips) const
         return false;
 
     const LenOption& rhs = (const LenOption&)ips;
-    return ( config == rhs.config and relative == rhs.relative );
+    return ( range == rhs.range and relative == rhs.relative );
 }
 
 IpsOption::EvalStatus LenOption::eval(Cursor& c, Packet*)
@@ -89,7 +89,7 @@ IpsOption::EvalStatus LenOption::eval(Cursor& c, Packet*)
     RuleProfile profile(lenCheckPerfStats);
     unsigned n = relative ? c.length() : c.size();
 
-    if ( config.eval(n) )
+    if ( range.eval(n) )
         return MATCH;
 
     return NO_MATCH;
@@ -134,6 +134,8 @@ public:
 bool LenModule::begin(const char*, int, SnortConfig*)
 {
     data.init();
+    relative = false;
+
     return true;
 }
 
index 48730f57a0d26ffb9e8527cc90a69e54f792ef39..1190d48b729a3fd68fbea8aa962413981b91a227 100644 (file)
@@ -695,6 +695,7 @@ ContentData* ContentModule::get_data()
 
 bool ContentModule::begin(const char*, int, SnortConfig*)
 {
+    delete cd;
     cd = new ContentData();
     return true;
 }
index c38bb3963e625d779ee54b9431c6bfc34068f807..d5181ea2d4a9c0ed9c9904fa2b56e78902bc43ef 100644 (file)
@@ -458,6 +458,7 @@ bool FlowbitsModule::begin(const char*, int, SnortConfig*)
 {
     delete fbc;
     bits.clear();
+    op = FlowBitCheck::Op::SET;
     return true;
 }
 
index a796be33eb3df22c3558aef63b43506c1359a20f..b8298e58493a8f910edaeb131fcec4053649b983 100644 (file)
@@ -309,7 +309,7 @@ HashMatchData* HashModule::get_data()
 
 bool HashModule::begin(const char*, int, SnortConfig*)
 {
-    assert(!hmd);
+    delete hmd;
     hmd = new HashMatchData;
     return true;
 }
@@ -317,7 +317,10 @@ bool HashModule::begin(const char*, int, SnortConfig*)
 bool HashModule::end(const char*, int, SnortConfig*)
 {
     if ( !hmd->length )
+    {
         ParseError("%s requires length parameter", get_name());
+        return false;
+    }
 
     return true;
 }
index 8221b7ffabdd4bc4147a6e0adabe683770e2e165..073547322f0e91e329af469fca1c863e7c17eb27 100644 (file)
@@ -60,7 +60,7 @@ struct RegexConfig
         re.clear();
         db = nullptr;
         pcre_upgrade = false;
-        pmd.flags = pmd.mpse_flags = 0;
+        pmd = { };
     }
 };
 
index f02dc7443d45f237f341daa91dd5c15c01d9d687..f072b69defaa39cb572891d8a592ed6f33ab6e88 100644 (file)
@@ -83,12 +83,8 @@ struct SdPatternConfig
     bool forced_boundary = false;
     int (* validate)(const uint8_t* buf, unsigned long long buflen) = nullptr;
 
-    inline bool operator==(const SdPatternConfig& rhs) const
-    {
-        if ( pii == rhs.pii and threshold == rhs.threshold )
-            return true;
-        return false;
-    }
+    bool operator==(const SdPatternConfig& rhs) const
+    { return pii == rhs.pii and threshold == rhs.threshold; }
 
     SdPatternConfig()
     { reset(); }
@@ -100,6 +96,7 @@ struct SdPatternConfig
         can_be_obfuscated = false;
         validate = nullptr;
         db = nullptr;
+        pmd = { };
     }
 };
 
@@ -411,7 +408,7 @@ bool SdPatternModule::begin(const char*, int, SnortConfig*)
         return false;
     }
 
-    config = SdPatternConfig();
+    config.reset();
     return true;
 }