Wireshark-dev: Re: [Wireshark-dev] Familiar with gtk/sctp_graph_dlg.c?

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Mon, 25 Apr 2011 21:23:22 -0700
On Apr 25, 2011, at 3:01 PM, Michael Tüxen wrote:

> dup_list = (guint32 *)((char *)sack_header + 16 + (nr * sizeof(struct gaps)))

Clang likes something that doesn't involve casting a "char *", which is not guaranteed to contain an address that's 4-byte aligned, to a "guint32 *", which is a pointer that's supposed to be 4-byte aligned...

...and that, on at least some architectures, *MUST* be 4-byte aligned in order for dereferences of it to work!

One such architecture is SPARC, which traps on unaligned references.  I think at least some versions of ARM are other such architectures; I don't think it traps on unaligned accesses,  but it might, for example, just act as if the lower 2 bits of the address are 0.

Unless sack_header is *guaranteed* to be aligned on a 4-byte boundary, that code is unsafe.