1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

msg_controllen has to be CMSG_SPACE so that the kernel can account for

each cmsg_len (ie. msg_controllen = sum of CMSG_ALIGN(cmsg_len).  This
works now that kernel fd passing has been fixed to accept a bit of
sloppiness because of this ABI repair.
lots of discussion with kettenis
This commit is contained in:
deraadt 2008-03-24 16:10:55 +00:00
parent 1b373d95a3
commit da15c7b92f
34 changed files with 118 additions and 151 deletions

View File

@ -451,7 +451,7 @@ Perl_dump_sv_child(pTHX_ SV *sv)
be open, the wait would be forever. */
msg.msg_control = control.control;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(control.control);
/* We're a connected socket so we don't need a destination */
msg.msg_name = NULL;
msg.msg_namelen = 0;
@ -716,7 +716,7 @@ perl_destruct(pTHXx)
int got_fd;
msg.msg_control = control.control;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(control.control);
/* We're a connected socket so we don't need a source */
msg.msg_name = NULL;
msg.msg_namelen = 0;

View File

@ -143,25 +143,24 @@ update_client_creds(int s, kcm_client *peer)
/* NetBSD */
if (peer->uid == -1) {
struct msghdr msg;
socklen_t crmsgspace, crmsglen;
socklen_t crmsgsize;
void *crmsg;
struct cmsghdr *cmp;
struct sockcred *sc;
memset(&msg, 0, sizeof(msg));
crmsgspace = CMSG_SPACE(SOCKCREDSIZE(NGROUPS));
crmsglen = CMSG_LEN(SOCKCREDSIZE(NGROUPS));
crmsgsize = CMSG_SPACE(SOCKCREDSIZE(NGROUPS));
if (crmsgsize == 0)
return 1 ;
crmsg = malloc(crmsgspace);
crmsg = malloc(crmsgsize);
if (crmsg == NULL)
goto failed_scm_creds;
memset(crmsg, 0, crmsgspace);
memset(crmsg, 0, crmsgsize);
msg.msg_control = crmsg;
msg.msg_controllen = crmsglen;
msg.msg_controllen = crmsgsize;
if (recvmsg(s, &msg, 0) < 0) {
free(crmsg);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: auth_subr.c,v 1.34 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: auth_subr.c,v 1.35 2008/03/24 16:10:59 deraadt Exp $ */
/*
* Copyright (c) 2000-2002,2004 Todd C. Miller <Todd.Miller@courtesan.com>
@ -995,7 +995,7 @@ _recv_fd(auth_session_t *as, int fd)
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if (recvmsg(fd, &msg, 0) < 0)
syslog(LOG_ERR, "recvmsg: %m");
else if (msg.msg_flags & MSG_TRUNC)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: monitor_fdpass.c,v 1.3 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: monitor_fdpass.c,v 1.4 2008/03/24 16:11:00 deraadt Exp $ */
/*
* Copyright (c) 2002 Matthieu Herrb
@ -44,7 +44,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;
@ -85,7 +85,7 @@ recv_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)
syslog(LOG_WARNING, "recv_fd: recvmsg(%d): %m", sock);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: login_skey.c,v 1.21 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: login_skey.c,v 1.22 2008/03/24 16:11:00 deraadt Exp $ */
/*
* Copyright (c) 2000, 2001, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
@ -270,7 +270,7 @@ send_fd(int sock)
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(cmsgbuf.buf);
cmp = CMSG_FIRSTHDR(&msg);
cmp->cmsg_len = CMSG_LEN(sizeof(int));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: login_tis.c,v 1.8 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: login_tis.c,v 1.9 2008/03/24 16:11:00 deraadt Exp $ */
/*
* Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
@ -296,7 +296,7 @@ send_fd(struct tis_connection *tc, int sock)
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(cmsgbuf.buf);
cmp = CMSG_FIRSTHDR(&msg);
cmp->cmsg_len = CMSG_LEN(sizeof(int));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tftp-proxy.c,v 1.4 2008/03/15 16:25:00 deraadt Exp $
/* $OpenBSD: tftp-proxy.c,v 1.5 2008/03/24 16:11:00 deraadt Exp $
*
* Copyright (c) 2005 DLS Internet Services
* Copyright (c) 2004, 2005 Camiel Dobbelaar, <cd@sentia.nl>
@ -164,7 +164,7 @@ main(int argc, char *argv[])
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct sockaddr_storage));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if (recvmsg(fd, &msg, 0) < 0) {
syslog(LOG_ERR, "recvmsg: %m");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tftpd.c,v 1.61 2008/03/15 16:25:00 deraadt Exp $ */
/* $OpenBSD: tftpd.c,v 1.62 2008/03/24 16:11:00 deraadt Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@ -37,7 +37,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)tftpd.c 5.13 (Berkeley) 2/26/91";*/
static char rcsid[] = "$OpenBSD: tftpd.c,v 1.61 2008/03/15 16:25:00 deraadt Exp $";
static char rcsid[] = "$OpenBSD: tftpd.c,v 1.62 2008/03/24 16:11:00 deraadt Exp $";
#endif /* not lint */
/*
@ -286,7 +286,7 @@ main(int argc, char *argv[])
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct sockaddr_storage));
msg.msg_controllen = sizeof(cmsgbuf.buf);
n = recvmsg(fd, &msg, 0);
if (n < 0) {
@ -330,7 +330,7 @@ main(int argc, char *argv[])
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct sockaddr_storage));
msg.msg_controllen = sizeof(cmsgbuf.buf);
i = recvmsg(fd, &msg, 0);
if (i > 0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: unfdpass.c,v 1.14 2008/03/15 16:49:15 hshoexer Exp $ */
/* $OpenBSD: unfdpass.c,v 1.15 2008/03/24 16:11:08 deraadt Exp $ */
/* $NetBSD: unfdpass.c,v 1.3 1998/06/24 23:51:30 thorpej Exp $ */
/*-
@ -173,7 +173,7 @@ main(int argc, char *argv[])
*/
(void) memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * 3);
msg.msg_controllen = sizeof(cmsgbuf.buf);
if (recvmsg(sock, &msg, 0) < 0)
err(1, "recvmsg");
@ -270,7 +270,7 @@ child(int sock)
(void) memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * 3);
msg.msg_controllen = sizeof(cmsgbuf.buf);
cmp = CMSG_FIRSTHDR(&msg);
cmp->cmsg_len = CMSG_LEN(sizeof(int) * 3);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: monitor_fdpass.c,v 1.15 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: monitor_fdpass.c,v 1.16 2008/03/24 16:11:08 deraadt Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
@ -50,7 +50,7 @@ mm_send_fd(int socket, int fd)
bzero(&msg, sizeof msg);
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;
@ -94,7 +94,7 @@ mm_receive_fd(int socket)
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(socket, &msg, 0)) == -1) {
log_error("mm_receive_fd: recvmsg");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: activate.c,v 1.8 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: activate.c,v 1.9 2008/03/24 16:11:08 deraadt Exp $ */
/* $NetBSD: activate.c,v 1.5 1995/04/23 10:33:18 cgd Exp $ */
/*
@ -129,7 +129,7 @@ send_reply(int so, int fd, int error)
*/
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;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep_fdpass.c,v 1.4 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: privsep_fdpass.c,v 1.5 2008/03/24 16:11:08 deraadt Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
@ -63,7 +63,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;
@ -105,7 +105,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__);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ping6.c,v 1.72 2008/03/15 16:10:11 kettenis Exp $ */
/* $OpenBSD: ping6.c,v 1.73 2008/03/24 16:11:08 deraadt Exp $ */
/* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */
/*
@ -264,7 +264,7 @@ main(int argc, char *argv[])
int ch, hold, packlen, preload, optval, ret_ga;
u_char *datap, *packet;
char *e, *target, *ifname = NULL, *gateway = NULL;
int ip6optlen = 0, ip6optspace = 0;
int ip6optlen = 0;
struct cmsghdr *scmsgp = NULL;
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
u_long lsockbufsize;
@ -498,8 +498,7 @@ main(int argc, char *argv[])
errx(1, "too many intermediate hops");
/*NOTREACHED*/
}
ip6optlen = ip6optspace + CMSG_LEN(rthlen);
ip6optspace += CMSG_SPACE(rthlen);
ip6optlen += CMSG_SPACE(rthlen);
}
if (options & F_NIGROUP) {
@ -680,26 +679,20 @@ main(int argc, char *argv[])
*/
/* Specify the outgoing interface and/or the source address */
if (usepktinfo) {
ip6optlen = ip6optspace + CMSG_LEN(sizeof(struct in6_pktinfo));
ip6optspace += CMSG_SPACE(sizeof(struct in6_pktinfo));
}
if (usepktinfo)
ip6optlen += CMSG_SPACE(sizeof(struct in6_pktinfo));
if (hoplimit != -1) {
ip6optlen = ip6optspace + CMSG_LEN(sizeof(int));
ip6optspace += CMSG_SPACE(sizeof(int));
}
if (hoplimit != -1)
ip6optlen += CMSG_SPACE(sizeof(int));
#ifdef IPV6_REACHCONF
if (options & F_REACHCONF) {
ip6optlen = ip6optspace + CMSG_LEN(0);
ip6optspace += CMSG_SPACE(0);
}
if (options & F_REACHCONF)
ip6optlen += CMSG_SPACE(0);
#endif
/* set IP6 packet options */
if (ip6optlen) {
if ((scmsg = malloc(ip6optspace)) == 0)
if ((scmsg = malloc(ip6optlen)) == 0)
errx(1, "can't allocate enough memory");
smsghdr.msg_control = (caddr_t)scmsg;
smsghdr.msg_controllen = ip6optlen;
@ -929,7 +922,7 @@ main(int argc, char *argv[])
m.msg_iov = iov;
m.msg_iovlen = 1;
m.msg_control = (caddr_t)&cmsgbuf.buf;
m.msg_controllen = CMSG_LEN(1024);
m.msg_controllen = sizeof(cmsgbuf.buf);
cc = recvmsg(s, &m, 0);
if (cc < 0) {

View File

@ -1,7 +1,7 @@
.\" $OpenBSD: CMSG_DATA.3,v 1.4 2008/03/15 16:27:48 deraadt Exp $
.\" $OpenBSD: CMSG_DATA.3,v 1.5 2008/03/24 16:11:07 deraadt Exp $
.\" Written by Jared Yanovich <jaredy@openbsd.org>
.\" Public domain, July 3, 2005
.Dd $Mdocdate: March 15 2008 $
.Dd $Mdocdate: March 24 2008 $
.Dt CMSG_DATA 3
.Os
.Sh NAME
@ -61,10 +61,9 @@ This routine determines the size in bytes of a control message,
which includes the control message header.
.Fa len
specifies the length of the data held by the control message.
This value is what is normally stored in
This value is what is normally stored in the
.Fa cmsg_len
and
.Fa msg_msgcontrollen .
of each control message.
This routine accounts for any alignment constraints on the beginning of
ancillary data.
.It Fn CMSG_NXTHDR mhdr cmsg
@ -99,7 +98,7 @@ union {
memset(&msg, 0, sizeof(msg));
msg.msg_control = &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));
@ -122,7 +121,7 @@ union {
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if (recvmsg(s, &msg, 0) == -1)
err(1, "recvmsg");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: monitor_fdpass.c,v 1.16 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: monitor_fdpass.c,v 1.17 2008/03/24 16:11:07 deraadt Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@ -50,7 +50,7 @@ mm_send_fd(int sock, int fd)
memset(&msg, 0, sizeof(msg));
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;
@ -96,7 +96,7 @@ mm_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) {
error("%s: recvmsg: %s", __func__, strerror(errno));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: buffer.c,v 1.38 2008/03/15 16:19:00 deraadt Exp $ */
/* $OpenBSD: buffer.c,v 1.39 2008/03/24 16:11:02 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -178,9 +178,9 @@ msgbuf_write(struct msgbuf *msgbuf)
if (buf != NULL && buf->fd != -1) {
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 = msg.msg_controllen;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
*(int *)CMSG_DATA(cmsg) = buf->fd;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: imsg.c,v 1.41 2008/03/15 16:25:00 deraadt Exp $ */
/* $OpenBSD: imsg.c,v 1.42 2008/03/24 16:11:02 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -57,7 +57,7 @@ imsg_read(struct imsgbuf *ibuf)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * 16);
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
if (errno != EINTR && errno != EAGAIN) {

View File

@ -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__);

View File

@ -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;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: packet.c,v 1.8 2008/03/15 16:25:00 deraadt Exp $ */
/* $OpenBSD: packet.c,v 1.9 2008/03/24 16:11:04 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@ -147,7 +147,7 @@ recv_packet(int fd, short event, void *bula)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct in6_pktinfo));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((r = recvmsg(fd, &msg, 0)) == -1) {
if (errno != EAGAIN && errno != EINTR)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: packet.c,v 1.24 2008/03/15 16:25:00 deraadt Exp $ */
/* $OpenBSD: packet.c,v 1.25 2008/03/24 16:11:04 deraadt Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@ -140,7 +140,7 @@ recv_packet(int fd, short event, void *bula)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct sockaddr_dl));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((r = recvmsg(fd, &msg, 0)) == -1) {
if (errno != EAGAIN && errno != EINTR)

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $OpenBSD: bundle.c,v 1.73 2008/03/15 16:25:00 deraadt Exp $
* $OpenBSD: bundle.c,v 1.74 2008/03/24 16:11:04 deraadt Exp $
*/
#include <sys/param.h>
@ -1418,7 +1418,7 @@ bundle_ReceiveDatalink(struct bundle *bundle, int s)
msg.msg_iov = iov;
msg.msg_iovlen = 1; /* Only send the version at the first pass */
msg.msg_control = cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * SEND_MAXFD);
msg.msg_controllen = sizeof(cmsgbuf.buf);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = sizeof cmsgbuf.buf;
cmsg->cmsg_level = SOL_SOCKET;
@ -1591,7 +1591,7 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
msg.msg_iovlen = 1;
msg.msg_iov = iov;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * nfd);
msg.msg_controllen = CMSG_SPACE(sizeof(int) * nfd);
msg.msg_flags = 0;
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = msg.msg_controllen;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: buffer.c,v 1.11 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: buffer.c,v 1.12 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -181,7 +181,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (buf != NULL && buf->fd != -1) {
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;
@ -204,7 +204,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (buf != NULL && buf->fd != -1) {
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;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: imsg.c,v 1.13 2008/03/15 16:25:00 deraadt Exp $ */
/* $OpenBSD: imsg.c,v 1.14 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -68,7 +68,7 @@ imsg_read(struct imsgbuf *ibuf)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * 16);
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
if (errno != EINTR && errno != EAGAIN) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: packet.c,v 1.9 2008/03/15 16:24:58 deraadt Exp $ */
/* $OpenBSD: packet.c,v 1.10 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@ -113,7 +113,7 @@ recv_packet(int fd, short event, void *bula)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(struct sockaddr_dl));
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((r = recvmsg(fd, &msg, 0)) == -1) {
if (errno != EINTR && errno != EAGAIN)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: route6d.c,v 1.50 2008/03/15 16:23:27 deraadt Exp $ */
/* $OpenBSD: route6d.c,v 1.51 2008/03/24 16:11:05 deraadt Exp $ */
/* $KAME: route6d.c,v 1.111 2006/10/25 06:38:13 jinmei Exp $ */
/*
@ -31,7 +31,7 @@
*/
#if 0
static char _rcsid[] = "$OpenBSD: route6d.c,v 1.50 2008/03/15 16:23:27 deraadt Exp $";
static char _rcsid[] = "$OpenBSD: route6d.c,v 1.51 2008/03/24 16:11:05 deraadt Exp $";
#endif
#include <stdio.h>
@ -965,7 +965,7 @@ sendpacket(struct sockaddr_in6 *sin6, int len)
} else {
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
m.msg_control = (caddr_t)&cmsgbuf.buf;
m.msg_controllen = CMSG_LEN(sizeof(struct in6_pktinfo));
m.msg_controllen = sizeof(cmsgbuf.buf);
cm = CMSG_FIRSTHDR(&m);
cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
cm->cmsg_level = IPPROTO_IPV6;
@ -1023,7 +1023,7 @@ riprecv(void)
m.msg_iov = iov;
m.msg_iovlen = 1;
m.msg_control = (caddr_t)&cmsgbuf.buf;
m.msg_controllen = CMSG_LEN(sizeof(struct in6_pktinfo));
m.msg_controllen = sizeof(cmsgbuf.buf);
if ((len = recvmsg(ripsock, &m, 0)) < 0) {
fatal("recvmsg");
/*NOTREACHED*/

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rtadvd.c,v 1.29 2008/03/18 19:32:18 deraadt Exp $ */
/* $OpenBSD: rtadvd.c,v 1.30 2008/03/24 16:11:05 deraadt Exp $ */
/* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */
/*
@ -67,10 +67,8 @@
struct msghdr rcvmhdr;
static u_char *rcvcmsgbuf;
static size_t rcvcmsgbufspace;
static size_t rcvcmsgbuflen;
static u_char *sndcmsgbuf = NULL;
static size_t sndcmsgbufspace;
static size_t sndcmsgbuflen;
volatile sig_atomic_t do_dump;
volatile sig_atomic_t do_die;
@ -1297,20 +1295,16 @@ sock_open()
static u_char answer[1500];
rcvcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_LEN(sizeof(int));
rcvcmsgbufspace = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
rcvcmsgbuf = (u_char *)malloc(rcvcmsgbufspace);
rcvcmsgbuf = (u_char *)malloc(rcvcmsgbuflen);
if (rcvcmsgbuf == NULL) {
syslog(LOG_ERR, "<%s> not enough core", __func__);
exit(1);
}
sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_LEN(sizeof(int));
sndcmsgbufspace = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
sndcmsgbuf = (u_char *)malloc(sndcmsgbufspace);
sndcmsgbuf = (u_char *)malloc(sndcmsgbuflen);
if (sndcmsgbuf == NULL) {
syslog(LOG_ERR, "<%s> not enough core", __func__);
exit(1);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: probe.c,v 1.11 2008/03/18 19:32:19 deraadt Exp $ */
/* $OpenBSD: probe.c,v 1.12 2008/03/24 16:11:05 deraadt Exp $ */
/* $KAME: probe.c,v 1.16 2002/06/10 20:00:36 itojun Exp $ */
/*
@ -64,13 +64,11 @@ int
probe_init(void)
{
int scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_LEN(sizeof(int));
int scmsgspace = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
static u_char *sndcmsgbuf = NULL;
if (sndcmsgbuf == NULL &&
(sndcmsgbuf = (u_char *)malloc(scmsgspace)) == NULL) {
(sndcmsgbuf = (u_char *)malloc(scmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__, "malloc failed");
return(-1);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rtsol.c,v 1.13 2008/03/18 19:32:19 deraadt Exp $ */
/* $OpenBSD: rtsol.c,v 1.14 2008/03/24 16:11:05 deraadt Exp $ */
/* $KAME: rtsol.c,v 1.15 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -73,20 +73,18 @@ int
sockopen(void)
{
static u_char *rcvcmsgbuf = NULL, *sndcmsgbuf = NULL;
int rcvcmsgspace, sndcmsgspace, rcvcmsglen, sndcmsglen, on;
int rcvcmsglen, sndcmsglen, on;
static u_char answer[1500];
struct icmp6_filter filt;
sndcmsglen = rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_LEN(sizeof(int));
sndcmsgspace = rcvcmsgspace = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsgspace)) == NULL) {
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"malloc for receive msghdr failed");
return(-1);
}
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsgspace)) == NULL) {
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"malloc for send msghdr failed");
return(-1);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: buffer.c,v 1.3 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: buffer.c,v 1.4 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -181,7 +181,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (buf != NULL && buf->fd != -1) {
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;
@ -204,7 +204,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (buf != NULL && buf->fd != -1) {
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;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: imsg.c,v 1.4 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: imsg.c,v 1.5 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -68,7 +68,7 @@ imsg_read(struct imsgbuf *ibuf)
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = CMSG_LEN(sizeof(int) * 16);
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
if (errno != EINTR && errno != EAGAIN) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep_fdpass.c,v 1.6 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: privsep_fdpass.c,v 1.7 2008/03/24 16:11:05 deraadt Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
@ -63,7 +63,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;
@ -105,7 +105,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", "receive_fd");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep_fdpass.c,v 1.6 2008/03/15 16:19:02 deraadt Exp $ */
/* $OpenBSD: privsep_fdpass.c,v 1.7 2008/03/24 16:11:06 deraadt Exp $ */
/*
* Copyright (c) 2002 Matthieu Herrb
@ -46,7 +46,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;
@ -87,7 +87,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__);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: traceroute6.c,v 1.44 2008/03/15 16:43:59 deraadt Exp $ */
/* $OpenBSD: traceroute6.c,v 1.45 2008/03/24 16:11:06 deraadt Exp $ */
/* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */
/*
@ -344,7 +344,7 @@ main(int argc, char *argv[])
{
int mib[4] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DEFHLIM };
char hbuf[NI_MAXHOST], src0[NI_MAXHOST], *ep;
int ch, i, on = 1, seq, rcvcmsglen, rcvcmsgspace, error, minlen;
int ch, i, on = 1, seq, rcvcmsglen, error, minlen;
struct addrinfo hints, *res;
static u_char *rcvcmsgbuf;
u_long probe, hops, lport;
@ -590,12 +590,10 @@ main(int argc, char *argv[])
rcvmhdr.msg_namelen = sizeof(Rcv);
rcvmhdr.msg_iov = rcviov;
rcvmhdr.msg_iovlen = 1;
rcvcmsgspace = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_LEN(sizeof(int));
CMSG_SPACE(sizeof(int));
if ((rcvcmsgbuf = malloc(rcvcmsgspace)) == NULL) {
if ((rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
fprintf(stderr, "traceroute6: malloc failed\n");
exit(1);
}