From: Oleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) Date: Mon, 31 Oct 2022 15:23:02 +0000 (+0000) Subject: Pull request #3643: ports: align fields of PortObject and PortObject2 X-Git-Tag: 3.1.47.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=397bd21b152f27ec6a3a58762817d28daa422e8e;p=thirdparty%2Fsnort3.git Pull request #3643: ports: align fields of PortObject and PortObject2 Merge in SNORT/snort3 from ~OSHUMEIK/snort3:fix_port_object to master Squashed commit of the following: commit 44b3c6115e248071e3258e148b82fc99ce25eefb Author: Oleksii Shumeiko Date: Fri Oct 28 15:57:05 2022 +0300 ports: align fields of PortObject and PortObject2 A static check added. --- diff --git a/src/ports/port_object2.cc b/src/ports/port_object2.cc index 28f0a7f06..467ccb251 100644 --- a/src/ports/port_object2.cc +++ b/src/ports/port_object2.cc @@ -38,6 +38,24 @@ using namespace snort; +static void check_structures() +{ + using po1 = PortObject; + using po2 = PortObject2; + + assert(sizeof(po1::name) == sizeof(po2::name)); + assert(sizeof(po1::id) == sizeof(po2::id)); + assert(sizeof(po1::hash) == sizeof(po2::hash)); + assert(sizeof(po1::item_list) == sizeof(po2::item_list)); + + assert(offsetof(po1, name) == offsetof(po2, name)); + assert(offsetof(po1, id) == offsetof(po2, id)); + assert(offsetof(po1, hash) == offsetof(po2, hash)); + assert(offsetof(po1, item_list) == offsetof(po2, item_list)); +} + +static int _check_structures __attribute__((unused)) = (static_cast(check_structures()), 0); + #define PO_EXTRA_RULE_CNT 25 //------------------------------------------------------------------------- diff --git a/src/ports/port_object2.h b/src/ports/port_object2.h index 409ef351e..bfaa244b9 100644 --- a/src/ports/port_object2.h +++ b/src/ports/port_object2.h @@ -39,9 +39,10 @@ struct PortObject; struct PortObject2 { // FIXIT-L convert char* to C++ string - // prefix of this struct must match first 3 items in PortObject + // prefix of this struct must match first 4 items in PortObject char* name; /* user name */ int id; /* internal tracking - compiling sets this value */ + mutable unsigned hash = 0; SF_LIST* item_list; /* list of port and port-range items */ snort::GHash* rule_hash; /* hash of rule (rule-indexes) in use */