From: Ken Steele Date: Fri, 20 Dec 2013 18:50:43 +0000 (-0500) Subject: More structures that need to be marked Packed. X-Git-Tag: suricata-2.1beta1~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c91b7fd3bc177961f6f0c074766ee7c6f9f8d931;p=thirdparty%2Fsuricata.git More structures that need to be marked Packed. These structures are cast from raw packet data, so they should be packed. The case is: typedef struct Foo_ { } Foo; Foo *f = (Foo *)pkt; --- diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 6ff984fb56..bdf7c5e7b8 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -92,7 +92,7 @@ static uint32_t sensor_id = 0; typedef struct Unified2ExtraDataHdr_ { uint32_t event_type; uint32_t event_length; -} Unified2ExtraDataHdr; +} __attribute__((__packed__)) Unified2ExtraDataHdr; /** * Unified2 Extra Data (currently used only for XFF) @@ -477,7 +477,7 @@ int Unified2Logger(ThreadVars *t, void *data, const Packet *p) typedef struct _FakeIPv4Hdr { IPV4Hdr ip4h; TCPHdr tcph; -} FakeIPv4Hdr; +} __attribute__((__packed__)) FakeIPv4Hdr; static int Unified2ForgeFakeIPv4Header(FakeIPv4Hdr *fakehdr, const Packet *p, int pkt_len, char invert) { @@ -507,7 +507,7 @@ static int Unified2ForgeFakeIPv4Header(FakeIPv4Hdr *fakehdr, const Packet *p, in typedef struct _FakeIPv6Hdr { IPV6Hdr ip6h; TCPHdr tcph; -} FakeIPv6Hdr; +} __attribute__((__packed__)) FakeIPv6Hdr; /** * \param payload_len length of the payload diff --git a/src/decode-ethernet.h b/src/decode-ethernet.h index 829601f9ce..2a6f86e936 100644 --- a/src/decode-ethernet.h +++ b/src/decode-ethernet.h @@ -45,7 +45,7 @@ typedef struct EthernetHdr_ { uint8_t eth_dst[6]; uint8_t eth_src[6]; uint16_t eth_type; -} EthernetHdr; +} __attribute__((__packed__)) EthernetHdr; #endif /* __DECODE_ETHERNET_H__ */ diff --git a/src/decode-gre.h b/src/decode-gre.h index 4dd0fa888a..e5a4f4c17c 100644 --- a/src/decode-gre.h +++ b/src/decode-gre.h @@ -37,7 +37,7 @@ typedef struct GREHdr_ uint8_t version; /**< GRE version */ uint16_t ether_type; /**< ether type of the encapsulated traffic */ -} GREHdr; +} __attribute__((__packed__)) GREHdr; typedef struct GRESreHdr_ { @@ -45,7 +45,7 @@ typedef struct GRESreHdr_ uint8_t sre_offset; uint8_t sre_length; uint8_t *routing; -} GRESreHdr; +} __attribute__((__packed__)) GRESreHdr; #define GRE_VERSION_0 0x0000 #define GRE_VERSION_1 0x0001 diff --git a/src/decode-icmpv4.h b/src/decode-icmpv4.h index 9f37c383ef..f8cb97f4f0 100644 --- a/src/decode-icmpv4.h +++ b/src/decode-icmpv4.h @@ -162,7 +162,7 @@ typedef struct ICMPV4Hdr_ uint8_t type; uint8_t code; uint16_t checksum; -} ICMPV4Hdr; +} __attribute__((__packed__)) ICMPV4Hdr; /* ICMPv4 header structure */ typedef struct ICMPV4ExtHdr_ diff --git a/src/decode-ipv4.h b/src/decode-ipv4.h index 3e0849fe6f..be212bf2fa 100644 --- a/src/decode-ipv4.h +++ b/src/decode-ipv4.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -84,7 +84,7 @@ typedef struct IPV4Hdr_ } ip4_un1; uint16_t ip_addrs[4]; } ip4_hdrun1; -} IPV4Hdr; +} __attribute__((__packed__)) IPV4Hdr; #define s_ip_src ip4_hdrun1.ip4_un1.ip_src diff --git a/src/decode-ipv6.h b/src/decode-ipv6.h index 9833e831a0..24dffb8fad 100644 --- a/src/decode-ipv6.h +++ b/src/decode-ipv6.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -47,7 +47,7 @@ typedef struct IPV6Hdr_ } ip6_un2; uint16_t ip6_addrs[16]; } ip6_hdrun2; -} IPV6Hdr; +} __attribute__((__packed__)) IPV6Hdr; #define s_ip6_src ip6_hdrun2.ip6_un2.ip6_src #define s_ip6_dst ip6_hdrun2.ip6_un2.ip6_dst @@ -126,7 +126,7 @@ typedef struct IPV6FragHdr_ uint8_t ip6fh_reserved; /* reserved field */ uint16_t ip6fh_offlg; /* offset, reserved, and flag */ uint32_t ip6fh_ident; /* identification */ -} IPV6FragHdr; +} __attribute__((__packed__)) IPV6FragHdr; #define IPV6_EXTHDR_GET_RAW_FH_NH(p) ((p)->ip6eh.ip6fh->ip6fh_nxt) #define IPV6_EXTHDR_GET_RAW_FH_HDRLEN(p) sizeof(IPV6FragHdr) @@ -149,13 +149,13 @@ typedef struct IPV6AuthHdr_ uint16_t ip6ah_reserved; /* reserved for future use */ uint32_t ip6ah_spi; /* SECURITY PARAMETERS INDEX (SPI) */ uint32_t ip6ah_seq; /* sequence number */ -} IPV6AuthHdr; +} __attribute__((__packed__)) IPV6AuthHdr; typedef struct IPV6EspHdr_ { uint32_t ip6esph_spi; /* SECURITY PARAMETERS INDEX (SPI) */ uint32_t ip6esph_seq; /* sequence number */ -} IPV6EspHdr; +} __attribute__((__packed__)) IPV6EspHdr; typedef struct IPV6RouteHdr_ { @@ -168,7 +168,7 @@ typedef struct IPV6RouteHdr_ uint8_t ip6rh0_num_addrs; /* number of actual addresses in the array/packet. The array is guarranteed to be filled up to this number. */ -} IPV6RouteHdr; +} __attribute__((__packed__)) IPV6RouteHdr; #define IPV6_EXTHDR_GET_RAW_RH_NH(p) ((p)->ip6eh.ip6rh->ip6rh_nxt) #define IPV6_EXTHDR_GET_RAW_RH_HDRLEN(p) ((p)->ip6eh.ip6rh->ip6rh_len) @@ -219,7 +219,7 @@ typedef struct IPV6HopOptsHdr_ uint8_t ip6hh_nxt; /* next header */ uint8_t ip6hh_len; /* header length in units of 8 bytes, not including first 8 bytes. */ -} IPV6HopOptsHdr; +} __attribute__((__packed__)) IPV6HopOptsHdr; #define IPV6_EXTHDR_GET_RAW_HH_NH(p) ((p)->ip6eh.ip6hh->ip6hh_nxt) #define IPV6_EXTHDR_GET_RAW_HH_HDRLEN(p) ((p)->ip6eh.ip6hh->ip6hh_len) @@ -234,7 +234,7 @@ typedef struct IPV6DstOptsHdr_ uint8_t ip6dh_nxt; /* next header */ uint8_t ip6dh_len; /* header length in units of 8 bytes, not including first 8 bytes. */ -} IPV6DstOptsHdr; +} __attribute__((__packed__)) IPV6DstOptsHdr; #define IPV6_EXTHDR_GET_RAW_DH1_NH(p) ((p)->ip6eh.ip6dh1->ip6dh_nxt) #define IPV6_EXTHDR_GET_RAW_DH1_HDRLEN(p) ((p)->ip6eh.ip6dh1->ip6dh_len) diff --git a/src/decode-ppp.h b/src/decode-ppp.h index bf39f4a423..00e61de9f9 100644 --- a/src/decode-ppp.h +++ b/src/decode-ppp.h @@ -65,7 +65,7 @@ typedef struct PPPHdr_ { uint8_t address; uint8_t control; uint16_t protocol; -} PPPHdr; +} __attribute__((__packed__)) PPPHdr; /** PPP Packet header length */ #define PPP_HEADER_LEN 4 diff --git a/src/decode-pppoe.h b/src/decode-pppoe.h index 1455ea57f4..6aecf74151 100644 --- a/src/decode-pppoe.h +++ b/src/decode-pppoe.h @@ -47,7 +47,7 @@ typedef struct PPPOEDiscoveryTag_ { uint16_t pppoe_tag_type; uint16_t pppoe_tag_length; -} PPPOEDiscoveryTag; +} __attribute__((__packed__)) PPPOEDiscoveryTag; typedef struct PPPOEDiscoveryHdr_ { @@ -55,7 +55,7 @@ typedef struct PPPOEDiscoveryHdr_ uint8_t pppoe_code; uint16_t discovery_id; uint16_t pppoe_length; -} PPPOEDiscoveryHdr; +} __attribute__((__packed__)) PPPOEDiscoveryHdr; /* see RFC 2516 - discovery codes */ #define PPPOE_CODE_PADI 0x09 diff --git a/src/decode-sctp.h b/src/decode-sctp.h index 878a583c28..184a172e60 100644 --- a/src/decode-sctp.h +++ b/src/decode-sctp.h @@ -40,7 +40,7 @@ typedef struct SCTPHdr_ uint16_t sh_dport; /* destination port */ uint32_t sh_vtag; /* verification tag, defined per flow */ uint32_t sh_sum; /* checksum, computed via crc32 */ -} SCTPHdr; +} __attribute__((__packed__)) SCTPHdr; #define CLEAR_SCTP_PACKET(p) { \ (p)->sctph = NULL; \ diff --git a/src/decode-sll.h b/src/decode-sll.h index ad8c7e6277..babdd7ac21 100644 --- a/src/decode-sll.h +++ b/src/decode-sll.h @@ -32,7 +32,7 @@ typedef struct SllHdr_ { uint16_t sll_halen; /* link-layer address length */ uint8_t sll_addr[8]; /* link-layer address */ uint16_t sll_protocol; /* protocol */ -} SllHdr; +} __attribute__((__packed__)) SllHdr; #endif /* __DECODE_SLL_H__ */ diff --git a/src/decode-vlan.h b/src/decode-vlan.h index c82e33be12..baa364726f 100644 --- a/src/decode-vlan.h +++ b/src/decode-vlan.h @@ -44,7 +44,7 @@ uint16_t DecodeVLANGetId(const struct Packet_ *, uint8_t layer); typedef struct VLANHdr_ { uint16_t vlan_cfi; uint16_t protocol; /**< protocol field */ -} VLANHdr; +} __attribute__((__packed__)) VLANHdr; /** VLAN header length */ #define VLAN_HEADER_LEN 4