From: Oleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) Date: Thu, 22 Sep 2022 14:34:44 +0000 (+0000) Subject: Pull request #3591: Content retry fix X-Git-Tag: 3.1.42.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d13ed67c44eceb961996c74af862b7ac6b2af432;p=thirdparty%2Fsnort3.git Pull request #3591: Content retry fix Merge in SNORT/snort3 from ~VHORBATO/snort3:content_retry_fix to master Squashed commit of the following: commit 2c16faf29f2f400e1439a46ad9e533cf99dc46c7 Author: Vitalii Date: Thu Sep 15 19:03:29 2022 +0300 parser: remove platform dependency from parse_int function commit 906ae2b9be21e7c1bc6916da9bac2dfddfb443b1 Author: Andrii Serbeniuk Date: Wed Sep 21 10:51:59 2022 +0300 ips_options: rollback changes causing content not to match when out of data start boundary --- diff --git a/src/ips_options/ips_content.cc b/src/ips_options/ips_content.cc index 2083d659f..acd2e19e4 100644 --- a/src/ips_options/ips_content.cc +++ b/src/ips_options/ips_content.cc @@ -306,8 +306,18 @@ static int uniSearchReal(ContentData* cd, Cursor& c) int64_t pos; if ( !c.get_delta() ) + { // first - adjust from cursor or buffer start pos = (cd->pmd.is_relative() ? c.get_pos() : 0) + offset; + + if ( pos < 0 ) + { + if ( depth ) + depth += pos; + + pos = 0; + } + } else { // retry - adjust from start of last match diff --git a/src/parser/parse_utils.cc b/src/parser/parse_utils.cc index b06650ff9..6508e67be 100644 --- a/src/parser/parse_utils.cc +++ b/src/parser/parse_utils.cc @@ -24,6 +24,7 @@ #include "parse_utils.h" #include +#include #include #include "log/messages.h" @@ -125,7 +126,9 @@ bool parse_byte_code(const char* in, bool& negate, std::string& out) int parse_int(const char* data, const char* tag, int low, int high) { - int32_t value = 0; + assert(low <= high); + + long value = 0; char* endptr = nullptr; value = SnortStrtol(data, &endptr, 10); @@ -133,22 +136,24 @@ int parse_int(const char* data, const char* tag, int low, int high) if (*endptr) { ParseError("invalid '%s' format.", tag); - return value; + return (int)value; } - if (errno == ERANGE) + if (errno == ERANGE || value > INT_MAX || value < INT_MIN) { ParseError("range problem on '%s' value.", tag); - return value; + errno = ERANGE; } - - if ((value > high) || (value < low)) + else if ((value > high) || (value < low)) { ParseError("'%s' must be in %d:%d, inclusive", tag, low, high); - return value; } - return value; + if (value > high) + return high; + else if (value < low) + return low; + return (int)value; } //-------------------------------------------------------------------------- @@ -183,7 +188,7 @@ TEST_CASE("parse_int", "[ParseUtils]") int res = parse_int(data, "test"); - CHECK(res == -1); + CHECK(res == 65535); CHECK(errno == ERANGE); } @@ -193,7 +198,7 @@ TEST_CASE("parse_int", "[ParseUtils]") int res = parse_int(data, "test"); - CHECK(res == 0); + CHECK(res == -65535); CHECK(errno == ERANGE); } @@ -201,14 +206,14 @@ TEST_CASE("parse_int", "[ParseUtils]") { int res = parse_int("1", "test", 2, 3); - CHECK(res == 1); + CHECK(res == 2); } SECTION("above the limit") { int res = parse_int("4", "test", 2, 3); - CHECK(res == 4); + CHECK(res == 3); } }