From 3b33de676ac8e84b82f40520ecd0f4722e16b349 Mon Sep 17 00:00:00 2001 From: Doug VanLeuven Date: Wed, 10 Oct 2012 22:10:14 +0000 Subject: zebra: kernel_socket: fix 64bit MacOS X alignment In OS X 10.7 zebra crashed on invalid execution address. sockaddr padding in *_msghdr is observed to be 4 bytes in 64bit OS X. The ROUNDUP macro assumed alignment on sizeof(long) which allocates 8 bytes on 64bit systems, 4 bytes on 32bit systems which is true for BSD generally. Test for Apple and use sizeof(int) which allocates 4 bytes on 32 & 64bit systems. Tested on 64bit OS X 10.7, FreeBSD 9.0 amd64 & i386 (32bit) using gcc & clang Signed-off-by: David Lamparter --- zebra/kernel_socket.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index b7061e76..ecc6e790 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -48,9 +48,15 @@ extern struct zebra_t zebrad; * XXX: why is ROUNDUP(0) sizeof(long)? 0 is an illegal sockaddr * length anyway (< sizeof (struct sockaddr)), so this shouldn't * matter. + * On OS X, both 32, 64bit syatems align on 4 byte boundary */ +#ifdef __APPLE__ +#define ROUNDUP(a) \ + ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int) - 1))) : sizeof(int)) +#else #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) +#endif /* * Given a pointer (sockaddr or void *), return the number of bytes -- cgit v1.2.1