Otto Moerbeek <[email protected]> wrote: > > right. So I have tried my patch (without the memcpy dance) on sparc64 > > over udp and tcp and I have also tracked this down in the code. This > > should be fine as is. ar->ar_data comes directly out of malloc > > (reallocarray) in ensure_ibuf() and the struct is defined thusly: > > > > struct asr_dns_header { > > uint16_t id; > > uint16_t flags; > > uint16_t qdcount; > > uint16_t ancount; > > uint16_t nscount; > > uint16_t arcount; > > }; > > > > So that is indeed safe as long as nobody starts allocating packet > buffers in different ways,
The common problem is in a libpcap parser, finding it in a packet. There, the 14-byte ethernet header comes into play, offsetting everything by 2 bytes. However, this struct has 2-byte alignment, so the compiler will generate safe alignment accesses. The problem really shows itself when you find per-byte packed encapsulation headers, due to an insufficient number of axe murderers lurking the halls of IETF. That would place these 2-byte objects at 1-byte alignment, and the compiler generated 2-byte instructions bomb. Such encapsulations are far more rare. The major libpcap parser (tcpdump) avoids this by always considering packets byte aligned..
