[Xcb] [PATCH libxcb] Fix alignment issues in FD passing code

Mark Kettenis mark.kettenis at xs4all.nl
Wed Nov 20 02:48:20 PST 2013

> Date: Mon, 18 Nov 2013 16:56:13 +0100
> From: Uli Schlachter <psychon at znc.in>
> Hi,
> On 12.11.2013 07:15, Matthieu Herrb wrote:
> > On Mon, Nov 11, 2013 at 11:11:56PM +0100, Mark Kettenis wrote:
> >> From: Mark Kettenis <kettenis at openbsd.org>
> >>
> >> A char array on the stack is not guaranteed to have more than byte alignment.
> >> This means that casting it to a 'struct cmsghdr' and accessing its members
> >> may result in unaligned access.  This will generate SIGBUS on struct
> >> alignment architectures like OpenBSD/sparc64.  The canonical solution is to
> >> use a union to force proper alignment.
> >>
> >> Signed-off-by: Mark Kettenis <kettenis at openbsd.org>
> > 
> > Reviewed-by: Matthieu Herrb <matthieu at herrb.eu>
> [...]
> No idea if this is "good enough" for whatever problems people can
> come up with (see "that other reply" from xorg-devel). However, this
> patch definitely improves the situation. Thus:


I think this defenitely is "good enough".  While "der Mouse" has a
valid point that the use of a union doesn't guarantee proper alignment
for all possible ancillary data, the fact that "struct cmsghdr" has an
"int" member means that alignment will be good enough for file
descriptor passing, sice file descriptors are "int" as well.

More information about the Xcb mailing list