]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
framework: initialize Packet member variables (#5259)
authorBrian Morris <bmorris2@cisco.com>
Fri, 10 Apr 2026 12:37:45 +0000 (07:37 -0500)
committerGitHub <noreply@github.com>
Fri, 10 Apr 2026 12:37:45 +0000 (07:37 -0500)
src/flow/test/flow_stubs.h
src/protocols/packet.h

index af5b143070da3bbdb91a6b17260e3f223d58525b..72df1f004b10c7dcde11bec4a4cc07f474f94ad2 100644 (file)
@@ -42,7 +42,6 @@ void DataBus::publish(unsigned, unsigned, Packet*, Flow*) { }
 
 Packet::Packet(bool)
 {
-    memset((char*) this , 0, sizeof(*this));
     ip_proto_next = IpProtocol::PROTO_NOT_SET;
     packet_flags = PKT_FROM_CLIENT;
 }
index 92d851033d70456b0482c874cf65ffde76c6220f..52da02879ac834a3c70e7a8d1f62b711c72e8daf 100644 (file)
@@ -128,27 +128,27 @@ struct SO_PUBLIC Packet
     Packet(const Packet&) = delete;
     Packet& operator=(const Packet&) = delete;
 
-    Flow* flow;   /* for session tracking */
+    Flow* flow = nullptr;   /* for session tracking */
     Endianness* endianness = nullptr;
     Obfuscator* obfuscator = nullptr;
 
-    uint64_t packet_flags;      /* special flags for the packet */
-    uint32_t xtradata_mask;
-    uint32_t proto_bits;        /* protocols contained within this packet */
+    uint64_t packet_flags = 0;      /* special flags for the packet */
+    uint32_t xtradata_mask = 0;
+    uint32_t proto_bits = 0;        /* protocols contained within this packet */
 
-    uint16_t alt_dsize;         /* size for detection (iff PKT_DETECT_LIMIT) */
+    uint16_t alt_dsize = 0;         /* size for detection (iff PKT_DETECT_LIMIT) */
 
-    uint8_t num_layers;         /* index into layers for next encap */
+    uint8_t num_layers = 0;         /* index into layers for next encap */
     // FIXIT-M Consider moving ip_proto_next below `pkth`.
-    IpProtocol ip_proto_next;      /* the protocol ID after IP and all IP6 extension */
-    bool disable_inspect;
+    IpProtocol ip_proto_next = IpProtocol::PROTO_NOT_SET;      /* the protocol ID after IP and all IP6 extension */
+    bool disable_inspect = false;
     mutable FilteringState filtering_state;
-    PduSection sect;
+    PduSection sect = PS_NONE;
 
     // nothing after this point is zeroed by reset() ...
     IpsContext* context = nullptr;
     Active* active = nullptr;
-    Active* active_inst;
+    Active* active_inst = nullptr;
     ActiveAction** action = nullptr;
     ActiveAction* action_inst = nullptr;
 
@@ -156,8 +156,8 @@ struct SO_PUBLIC Packet
     SFDAQInstance* daq_instance = nullptr;  // DAQ instance the message came from
 
     // Everything beyond this point is set by PacketManager::decode()
-    const DAQ_PktHdr_t* pkth;   // packet meta data
-    const uint8_t* pkt;         // raw packet data
+    const DAQ_PktHdr_t* pkth = nullptr;   // packet meta data
+    const uint8_t* pkt = nullptr;         // raw packet data
     uint32_t pktlen = 0;        // raw packet data length
 
     // These are both set before PacketManager::decode() returns
@@ -165,18 +165,18 @@ struct SO_PUBLIC Packet
     uint16_t dsize = 0;             /* packet payload size */
 
     DecodeData ptrs; // convenience pointers used throughout Snort++
-    Layer* layers;    /* decoded encapsulations */
+    Layer* layers = nullptr;    /* decoded encapsulations */
 
     PseudoPacketType pseudo_type = PSEUDO_PKT_MAX;  // valid only when PKT_PSEUDO is set
 
-    uint64_t user_inspection_policy_id;
-    uint64_t user_ips_policy_id;
-    uint64_t user_network_policy_id;
+    uint64_t user_inspection_policy_id = 0;
+    uint64_t user_ips_policy_id = 0;
+    uint64_t user_network_policy_id = 0;
 
-    uint64_t inspection_started_timestamp;
+    uint64_t inspection_started_timestamp = 0;
 
-    uint8_t vlan_idx;
-    uint8_t ts_packet_flags; // FIXIT-M packet flags should always be thread safe
+    uint8_t vlan_idx = 0;
+    uint8_t ts_packet_flags = 0; // FIXIT-M packet flags should always be thread safe
 
     // IP_MAXPACKET is the minimum allowable max_dsize
     // there is no requirement that all data fit into an IP datagram
@@ -406,7 +406,7 @@ struct SO_PUBLIC Packet
     int inject();
 
 private:
-    bool allocated;
+    bool allocated = false;
 };
 
 #define BIT(i) (0x1 << ((i)-1))
@@ -476,4 +476,3 @@ inline uint64_t alignedNtohq(const uint64_t* ptr)
 }
 }
 #endif
-