From c2debddb2cd2ab8b0eff87ce37578c1f78f6864d Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 3 Feb 2018 20:10:19 -0800 Subject: Don't assume address data is aligned. The data for an address is *not* guaranteed to be aligned on any particular boundary, so, for IPv4 addresses, don't assume it's aligned on a 32-bit boundary - to get it in host byte order, fetch it with pntoh32(), which fetches a 32-bit value that's in network byte order, and isn't necessarily aligned on any particular boundary, and returns it in host byte order. Change-Id: Ic512ab4b1e0f2815d9f0af0e33714f456a08a45d Reviewed-on: https://code.wireshark.org/review/25589 Reviewed-by: Guy Harris --- epan/dissectors/packet-icmp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'epan/dissectors/packet-icmp.c') diff --git a/epan/dissectors/packet-icmp.c b/epan/dissectors/packet-icmp.c index 670640ab21..7a9e06eabd 100644 --- a/epan/dissectors/packet-icmp.c +++ b/epan/dissectors/packet-icmp.c @@ -46,6 +46,8 @@ #include #include +#include + #include "packet-ip.h" #include "packet-icmp.h" @@ -363,17 +365,19 @@ static const value_string interface_role_str[] = { #define MPLS_EXTENDED_PAYLOAD_C_TYPE 1 /* Return true if the address is in the 224.0.0.0/4 network block */ -#define is_a_multicast_addr(a) in4_addr_is_multicast(g_ntohl(a)) +#define is_a_multicast_addr(a) in4_addr_is_multicast(a) /* Return true if the address is the 255.255.255.255 broadcast address */ -#define is_a_broadcast_addr(a) \ - (g_ntohl(a) == 0xffffffff) +#define is_a_broadcast_addr(a) ((a) == 0xffffffffU) +/* + * XXX - should these be checking the address *type*, instead? + */ #define ADDR_IS_MULTICAST(addr) \ - (((addr)->len == 4) && is_a_multicast_addr(*(const guint32 *)((addr)->data))) + (((addr)->len == 4) && is_a_multicast_addr(pntoh32((addr)->data))) #define ADDR_IS_BROADCAST(addr) \ - (((addr)->len == 4) && is_a_broadcast_addr(*(const guint32 *)((addr)->data))) + (((addr)->len == 4) && is_a_broadcast_addr(pntoh32((addr)->data))) #define ADDR_IS_NOT_UNICAST(addr) \ (ADDR_IS_MULTICAST(addr) || ADDR_IS_BROADCAST(addr)) -- cgit v1.2.3