]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3643: ports: align fields of PortObject and PortObject2
authorOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Mon, 31 Oct 2022 15:23:02 +0000 (15:23 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Mon, 31 Oct 2022 15:23:02 +0000 (15:23 +0000)
Merge in SNORT/snort3 from ~OSHUMEIK/snort3:fix_port_object to master

Squashed commit of the following:

commit 44b3c6115e248071e3258e148b82fc99ce25eefb
Author: Oleksii Shumeiko <oshumeik@cisco.com>
Date:   Fri Oct 28 15:57:05 2022 +0300

    ports: align fields of PortObject and PortObject2

    A static check added.

src/ports/port_object2.cc
src/ports/port_object2.h

index 28f0a7f063b45ce00df193bc6608d72441bdf1e5..467ccb2511c3c52d059ab01b80ff442a9124eb12 100644 (file)
 
 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<void>(check_structures()), 0);
+
 #define PO_EXTRA_RULE_CNT 25
 
 //-------------------------------------------------------------------------
index 409ef351ea9c1a63b8d29c0dfa798f4e14bc037d..bfaa244b91592e60a03833e074a64e9eb86738b8 100644 (file)
@@ -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 */