diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-03-13 01:49:54 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-03-13 01:49:54 +0000 |
commit | f806a02a48dffd4879055cd8cdc1895a0a6c926e (patch) | |
tree | 6c61227927ac37c4d373490dda12a0ed461491c8 /sbin | |
parent | 2d29c72143d0f8408606ffb11045f029da0762f6 (diff) |
Correct CMSG_SPACE and CMSG_LEN usage everywhere in the tree. Due to
an extensive discussion with otto, kettenis, millert, and hshoexer
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/isakmpd/monitor_fdpass.c | 18 | ||||
-rw-r--r-- | sbin/mount_portal/activate.c | 20 | ||||
-rw-r--r-- | sbin/pflogd/privsep_fdpass.c | 20 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 11 |
4 files changed, 40 insertions, 29 deletions
diff --git a/sbin/isakmpd/monitor_fdpass.c b/sbin/isakmpd/monitor_fdpass.c index 2ead0b48896..aef0e998bd8 100644 --- a/sbin/isakmpd/monitor_fdpass.c +++ b/sbin/isakmpd/monitor_fdpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor_fdpass.c,v 1.13 2008/03/02 18:47:29 hshoexer Exp $ */ +/* $OpenBSD: monitor_fdpass.c,v 1.14 2008/03/13 01:49:52 deraadt Exp $ */ /* * Copyright 2001 Niels Provos <provos@citi.umich.edu> @@ -41,16 +41,16 @@ mm_send_fd(int socket, int fd) struct msghdr msg; union { struct cmsghdr hdr; - char tmp[CMSG_SPACE(sizeof(int))]; - } tmp; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; char ch = '\0'; struct cmsghdr *cmsg; struct iovec vec; ssize_t n; bzero(&msg, sizeof msg); - 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; @@ -80,8 +80,8 @@ mm_receive_fd(int socket) struct msghdr msg; union { struct cmsghdr hdr; - char tmp[CMSG_SPACE(sizeof(int))]; - } tmp; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; char ch; struct cmsghdr *cmsg; struct iovec vec; @@ -93,8 +93,8 @@ mm_receive_fd(int socket) vec.iov_len = 1; msg.msg_iov = &vec; msg.msg_iovlen = 1; - msg.msg_control = &tmp; - msg.msg_controllen = sizeof tmp; + msg.msg_control = &cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); if ((n = recvmsg(socket, &msg, 0)) == -1) { log_error("mm_receive_fd: recvmsg"); diff --git a/sbin/mount_portal/activate.c b/sbin/mount_portal/activate.c index 636592df280..a3b1ed157ed 100644 --- a/sbin/mount_portal/activate.c +++ b/sbin/mount_portal/activate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: activate.c,v 1.6 2003/06/11 06:22:14 deraadt Exp $ */ +/* $OpenBSD: activate.c,v 1.7 2008/03/13 01:49:52 deraadt Exp $ */ /* $NetBSD: activate.c,v 1.5 1995/04/23 10:33:18 cgd Exp $ */ /* @@ -103,10 +103,11 @@ send_reply(int so, int fd, int error) int n; struct iovec iov; struct msghdr msg; + struct cmsghdr *cmsg; struct { struct cmsghdr cmsg; - int fd; - } ctl; + u_char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; /* * Line up error code. Don't worry about byte ordering @@ -127,12 +128,13 @@ send_reply(int so, int fd, int error) * construct a suitable rights control message. */ if (fd >= 0) { - ctl.fd = fd; - ctl.cmsg.cmsg_len = sizeof(ctl); - ctl.cmsg.cmsg_level = SOL_SOCKET; - ctl.cmsg.cmsg_type = SCM_RIGHTS; - msg.msg_control = (caddr_t)&ctl; - msg.msg_controllen = ctl.cmsg.cmsg_len; + 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; + cmsg->cmsg_type = SCM_RIGHTS; + *(int *)CMSG_DATA(cmsg) = fd; } /* diff --git a/sbin/pflogd/privsep_fdpass.c b/sbin/pflogd/privsep_fdpass.c index 50afdfc2859..f6e23dfe031 100644 --- a/sbin/pflogd/privsep_fdpass.c +++ b/sbin/pflogd/privsep_fdpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep_fdpass.c,v 1.2 2004/08/13 02:51:48 djm Exp $ */ +/* $OpenBSD: privsep_fdpass.c,v 1.3 2008/03/13 01:49:53 deraadt Exp $ */ /* * Copyright 2001 Niels Provos <provos@citi.umich.edu> @@ -50,7 +50,10 @@ void send_fd(int sock, int fd) { struct msghdr msg; - char tmp[CMSG_SPACE(sizeof(int))]; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; struct cmsghdr *cmsg; struct iovec vec; int result = 0; @@ -59,8 +62,8 @@ send_fd(int sock, int fd) memset(&msg, 0, sizeof(msg)); if (fd >= 0) { - 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; @@ -86,7 +89,10 @@ int receive_fd(int sock) { struct msghdr msg; - char tmp[CMSG_SPACE(sizeof(int))]; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; struct cmsghdr *cmsg; struct iovec vec; ssize_t n; @@ -98,8 +104,8 @@ receive_fd(int sock) vec.iov_len = sizeof(int); msg.msg_iov = &vec; msg.msg_iovlen = 1; - msg.msg_control = tmp; - msg.msg_controllen = sizeof(tmp); + msg.msg_control = &cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); if ((n = recvmsg(sock, &msg, 0)) == -1) warn("%s: recvmsg", __func__); diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index d222d27b1c7..005b6a0b1b7 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.70 2007/12/30 13:38:47 sobrado Exp $ */ +/* $OpenBSD: ping6.c,v 1.71 2008/03/13 01:49:53 deraadt Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -873,7 +873,10 @@ main(int argc, char *argv[]) for (;;) { struct msghdr m; - u_char buf[1024]; + union { + struct cmsghdr hdr; + u_char buf[sizeof(struct in6_pktinfo)]; + } cmsgbuf; struct iovec iov[2]; /* signal handling */ @@ -919,8 +922,8 @@ main(int argc, char *argv[]) iov[0].iov_len = packlen; m.msg_iov = iov; m.msg_iovlen = 1; - m.msg_control = (caddr_t)buf; - m.msg_controllen = sizeof(buf); + m.msg_control = (caddr_t)&cmsgbuf.buf; + m.msg_controllen = sizeof(cmsgbuf.buf); cc = recvmsg(s, &m, 0); if (cc < 0) { |