diff options
author | des <des@FreeBSD.org> | 2008-07-30 09:16:46 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2008-07-30 09:16:46 +0000 |
commit | 0c146c189c9a742f1346ef7f1e073813fb958f2c (patch) | |
tree | a7c29b799f2ecf52090e9cd19c9463db2a63e999 | |
parent | 1e5899ea8b9164e8360d3fda61a0c134471ce14f (diff) | |
download | FreeBSD-src-0c146c189c9a742f1346ef7f1e073813fb958f2c.zip FreeBSD-src-0c146c189c9a742f1346ef7f1e073813fb958f2c.tar.gz |
Fix alignment of the cmsg buffer by placing it in a union with a struct
cmsghdr. Derived from upstream patch.
Submitted by: cognet
MFC after: 2 weeks
-rw-r--r-- | crypto/openssh/monitor_fdpass.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crypto/openssh/monitor_fdpass.c b/crypto/openssh/monitor_fdpass.c index 9f8e9cd..6eb55c6 100644 --- a/crypto/openssh/monitor_fdpass.c +++ b/crypto/openssh/monitor_fdpass.c @@ -49,7 +49,10 @@ mm_send_fd(int sock, int fd) char ch = '\0'; ssize_t n; #ifndef HAVE_ACCRIGHTS_IN_MSGHDR - char tmp[CMSG_SPACE(sizeof(int))]; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; struct cmsghdr *cmsg; #endif @@ -58,8 +61,8 @@ mm_send_fd(int sock, int fd) msg.msg_accrights = (caddr_t)&fd; msg.msg_accrightslen = sizeof(fd); #else - msg.msg_control = (caddr_t)tmp; - msg.msg_controllen = CMSG_LEN(sizeof(int)); + msg.msg_control = (caddr_t)&cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_level = SOL_SOCKET; @@ -94,7 +97,10 @@ mm_receive_fd(int sock) char ch; int fd; #ifndef HAVE_ACCRIGHTS_IN_MSGHDR - char tmp[CMSG_SPACE(sizeof(int))]; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; struct cmsghdr *cmsg; #endif @@ -107,8 +113,8 @@ mm_receive_fd(int sock) msg.msg_accrights = (caddr_t)&fd; msg.msg_accrightslen = sizeof(fd); #else - msg.msg_control = tmp; - msg.msg_controllen = sizeof(tmp); + msg.msg_control = &cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); #endif if ((n = recvmsg(sock, &msg, 0)) == -1) |