diff options
Diffstat (limited to 'usr.sbin/bind/lib/isc')
-rw-r--r-- | usr.sbin/bind/lib/isc/unix/privsep_fdpass.c | 6 | ||||
-rw-r--r-- | usr.sbin/bind/lib/isc/unix/socket.c | 42 |
2 files changed, 18 insertions, 30 deletions
diff --git a/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c b/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c index 444889a8074..5a59e0bda73 100644 --- a/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c +++ b/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep_fdpass.c,v 1.6 2008/03/15 16:33:58 deraadt Exp $ */ +/* $OpenBSD: privsep_fdpass.c,v 1.7 2008/03/24 16:11:02 deraadt Exp $ */ /* * Copyright 2001 Niels Provos <provos@citi.umich.edu> @@ -61,7 +61,7 @@ send_fd(int sock, int fd) if (fd >= 0) { msg.msg_control = (caddr_t)&cmsgbuf.buf; - msg.msg_controllen = CMSG_LEN(sizeof(int)); + msg.msg_controllen = sizeof(cmsgbuf.buf); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_level = SOL_SOCKET; @@ -102,7 +102,7 @@ receive_fd(int sock) msg.msg_iov = &vec; msg.msg_iovlen = 1; msg.msg_control = &cmsgbuf.buf; - msg.msg_controllen = CMSG_LEN(sizeof(int)); + msg.msg_controllen = sizeof(cmsgbuf.buf); if ((n = recvmsg(sock, &msg, 0)) == -1) warn("%s: recvmsg", __func__); diff --git a/usr.sbin/bind/lib/isc/unix/socket.c b/usr.sbin/bind/lib/isc/unix/socket.c index 74003115a47..5f6583dc5e4 100644 --- a/usr.sbin/bind/lib/isc/unix/socket.c +++ b/usr.sbin/bind/lib/isc/unix/socket.c @@ -190,10 +190,8 @@ struct isc_socket { #endif char *recvcmsgbuf; - ISC_SOCKADDR_LEN_T recvcmsgbufspace; ISC_SOCKADDR_LEN_T recvcmsgbuflen; char *sendcmsgbuf; - ISC_SOCKADDR_LEN_T sendcmsgbufspace; ISC_SOCKADDR_LEN_T sendcmsgbuflen; }; @@ -513,14 +511,11 @@ cmsg_space(ISC_SOCKADDR_LEN_T len) { * XXX: The buffer length is an ad-hoc value, but should be enough * in a practical sense. */ - union { - struct cmsghdr hdr; - char buf[cmsg_sizeof(struct cmsghdr) + 1024]; - }; + char dummybuf[sizeof(struct cmsghdr) + 1024]; memset(&msg, 0, sizeof(msg)); msg.msg_control = dummybuf; - msg.msg_controllen = cmsg_len(sizeof(cmsg_sizeof(struct cmsghdr) + 1024)); + msg.msg_controllen = sizeof(dummybuf); cmsgp = (struct cmsghdr *)dummybuf; cmsgp->cmsg_len = cmsg_len(len); @@ -726,7 +721,7 @@ build_msghdr_send(isc_socket_t *sock, isc_socketevent_t *dev, "sendto pktinfo data, ifindex %u", dev->pktinfo.ipi6_ifindex); - msg->msg_controllen = cmsg_len(sizeof(struct in6_pktinfo)); + msg->msg_controllen = cmsg_space(sizeof(struct in6_pktinfo)); INSIST(msg->msg_controllen <= sock->sendcmsgbuflen); msg->msg_control = (void *)sock->sendcmsgbuf; @@ -867,7 +862,7 @@ build_msghdr_recv(isc_socket_t *sock, isc_socketevent_t *dev, msg->msg_flags = 0; #if defined(USE_CMSG) if (sock->type == isc_sockettype_udp) { - msg->msg_control = sock->recvcmsgbuf; + msg->msg_control = sock->recvcmsgbuf; msg->msg_controllen = sock->recvcmsgbuflen; } #endif /* USE_CMSG */ @@ -1262,7 +1257,7 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, { isc_socket_t *sock; isc_result_t result; - ISC_SOCKADDR_LEN_T cmsgbuflen, cmsgbufspace; + ISC_SOCKADDR_LEN_T cmsgbuflen; sock = isc_mem_get(manager->mctx, sizeof(*sock)); @@ -1287,33 +1282,26 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, * set up cmsg buffers */ cmsgbuflen = 0; - cmsgbufspace = 0; #if defined(USE_CMSG) && defined(ISC_PLATFORM_HAVEIN6PKTINFO) - cmsgbuflen = cmsgbufspace + cmsg_len(sizeof(struct in6_pktinfo)); - cmsgbufspace += cmsg_space(sizeof(struct in6_pktinfo)); + cmsgbuflen = cmsg_space(sizeof(struct in6_pktinfo)); #endif #if defined(USE_CMSG) && defined(SO_TIMESTAMP) - cmsgbuflen = cmsgbufspace + cmsg_len(sizeof(struct timeval)); - cmsgbufspace += cmsg_space(sizeof(struct timeval)); + cmsgbuflen += cmsg_space(sizeof(struct timeval)); #endif sock->recvcmsgbuflen = cmsgbuflen; - sock->recvcmsgbufspace = cmsgbufspace; - if (sock->recvcmsgbufspace != 0U) { - sock->recvcmsgbuf = isc_mem_get(manager->mctx, cmsgbufspace); + if (sock->recvcmsgbuflen != 0U) { + sock->recvcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen); if (sock->recvcmsgbuf == NULL) goto error; } cmsgbuflen = 0; - cmsgbufspace = 0; #if defined(USE_CMSG) && defined(ISC_PLATFORM_HAVEIN6PKTINFO) - cmsgbuflen = cmsgbufspace + cmsg_len(sizeof(struct in6_pktinfo)); - cmsgbufspace += cmsg_space(sizeof(struct in6_pktinfo)); + cmsgbuflen = cmsg_space(sizeof(struct in6_pktinfo)); #endif sock->sendcmsgbuflen = cmsgbuflen; - sock->sendcmsgbufspace = cmsgbufspace; if (sock->sendcmsgbuflen != 0U) { - sock->sendcmsgbuf = isc_mem_get(manager->mctx, cmsgbufspace); + sock->sendcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen); if (sock->sendcmsgbuf == NULL) goto error; } @@ -1360,10 +1348,10 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, error: if (sock->recvcmsgbuf != NULL) isc_mem_put(manager->mctx, sock->recvcmsgbuf, - sock->recvcmsgbufspace); + sock->recvcmsgbuflen); if (sock->sendcmsgbuf != NULL) isc_mem_put(manager->mctx, sock->sendcmsgbuf, - sock->sendcmsgbufspace); + sock->sendcmsgbuflen); isc_mem_put(manager->mctx, sock, sizeof(*sock)); return (result); @@ -1393,10 +1381,10 @@ free_socket(isc_socket_t **socketp) { if (sock->recvcmsgbuf != NULL) isc_mem_put(sock->manager->mctx, sock->recvcmsgbuf, - sock->recvcmsgbufspace); + sock->recvcmsgbuflen); if (sock->sendcmsgbuf != NULL) isc_mem_put(sock->manager->mctx, sock->sendcmsgbuf, - sock->sendcmsgbufspace); + sock->sendcmsgbuflen); sock->magic = 0; |