From: Yehor Velykozhon -X (yvelykoz - SOFTSERVE INC at Cisco) Date: Mon, 2 Dec 2024 10:07:29 +0000 (+0000) Subject: Pull request #4531: bufferlen: reset "relative" flag in module::begin method X-Git-Tag: 3.6.0.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d62213f170a3e08c552f0936d889ba46d25ca64a;p=thirdparty%2Fsnort3.git Pull request #4531: bufferlen: reset "relative" flag in module::begin method Merge in SNORT/snort3 from ~YVELYKOZ/snort3:bufferlen_reinit to master Squashed commit of the following: commit f86e73e67019cc5d99758284b68ebf89ce5b8182 Author: Yehor Velykozhon Date: Wed Nov 27 12:48:19 2024 +0200 bufferlen: reset "relative" flag in module::begin method commit 256ee2c838d7b44f77e7afaee64a12b86f5ad43f Author: Yehor Velykozhon Date: Wed Nov 27 14:35:52 2024 +0200 ips_options: update module::begin and other in several ips options --- diff --git a/src/ips_options/ips_bufferlen.cc b/src/ips_options/ips_bufferlen.cc index fbfbcd84a..c408bb834 100644 --- a/src/ips_options/ips_bufferlen.cc +++ b/src/ips_options/ips_bufferlen.cc @@ -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; } diff --git a/src/ips_options/ips_content.cc b/src/ips_options/ips_content.cc index 48730f57a..1190d48b7 100644 --- a/src/ips_options/ips_content.cc +++ b/src/ips_options/ips_content.cc @@ -695,6 +695,7 @@ ContentData* ContentModule::get_data() bool ContentModule::begin(const char*, int, SnortConfig*) { + delete cd; cd = new ContentData(); return true; } diff --git a/src/ips_options/ips_flowbits.cc b/src/ips_options/ips_flowbits.cc index c38bb3963..d5181ea2d 100644 --- a/src/ips_options/ips_flowbits.cc +++ b/src/ips_options/ips_flowbits.cc @@ -458,6 +458,7 @@ bool FlowbitsModule::begin(const char*, int, SnortConfig*) { delete fbc; bits.clear(); + op = FlowBitCheck::Op::SET; return true; } diff --git a/src/ips_options/ips_hash.cc b/src/ips_options/ips_hash.cc index a796be33e..b8298e584 100644 --- a/src/ips_options/ips_hash.cc +++ b/src/ips_options/ips_hash.cc @@ -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; } diff --git a/src/ips_options/ips_regex.cc b/src/ips_options/ips_regex.cc index 8221b7ffa..073547322 100644 --- a/src/ips_options/ips_regex.cc +++ b/src/ips_options/ips_regex.cc @@ -60,7 +60,7 @@ struct RegexConfig re.clear(); db = nullptr; pcre_upgrade = false; - pmd.flags = pmd.mpse_flags = 0; + pmd = { }; } }; diff --git a/src/ips_options/ips_sd_pattern.cc b/src/ips_options/ips_sd_pattern.cc index f02dc7443..f072b69de 100644 --- a/src/ips_options/ips_sd_pattern.cc +++ b/src/ips_options/ips_sd_pattern.cc @@ -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; }