From: Brian Morris Date: Fri, 10 Apr 2026 12:37:45 +0000 (-0500) Subject: framework: initialize Packet member variables (#5259) X-Git-Tag: 3.12.2.0~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cfa07ab212d100e3fe9a2db7ab702ca05a7bd31;p=thirdparty%2Fsnort3.git framework: initialize Packet member variables (#5259) --- diff --git a/src/flow/test/flow_stubs.h b/src/flow/test/flow_stubs.h index af5b14307..72df1f004 100644 --- a/src/flow/test/flow_stubs.h +++ b/src/flow/test/flow_stubs.h @@ -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; } diff --git a/src/protocols/packet.h b/src/protocols/packet.h index 92d851033..52da02879 100644 --- a/src/protocols/packet.h +++ b/src/protocols/packet.h @@ -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 -