summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2020-05-08 11:14:36 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2020-05-08 11:14:36 +0000
commite21ab7cec767ec1d96181b3a7ed63e65c7dbe058 (patch)
treec1e2093a47c0a91e9557e2efa7c12c8facdd6a8b /usr.bin
parente53b9d5be84bd1faab0dd8da57bb6d899cda8e94 (diff)
Make sure cmsgbufs are properly aligned by using the idiom from the
CMSG_DATA man page. Avoids SIGBUS on landisk; ok kettenis@ jca@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dig/lib/isc/unix/socket.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.bin/dig/lib/isc/unix/socket.c b/usr.bin/dig/lib/isc/unix/socket.c
index 0a2ea57e29e..dd803bc27a8 100644
--- a/usr.bin/dig/lib/isc/unix/socket.c
+++ b/usr.bin/dig/lib/isc/unix/socket.c
@@ -834,9 +834,14 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) {
struct msghdr msghdr;
isc_buffer_t *buffer;
int recv_errno;
- char cmsgbuf[RECVCMSGBUFLEN] = {0};
+ union {
+ struct msghdr msghdr;
+ char m[RECVCMSGBUFLEN];
+ } cmsgbuf;
+
+ memset(&cmsgbuf, 0, sizeof(cmsgbuf));
- build_msghdr_recv(sock, cmsgbuf, dev, &msghdr, iov, &read_count);
+ build_msghdr_recv(sock, cmsgbuf.m, dev, &msghdr, iov, &read_count);
cc = recvmsg(sock->fd, &msghdr, 0);
recv_errno = errno;
@@ -989,9 +994,14 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) {
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
int attempts = 0;
int send_errno;
- char cmsgbuf[SENDCMSGBUFLEN] = {0};
-
- build_msghdr_send(sock, cmsgbuf, dev, &msghdr, iov, &write_count);
+ union {
+ struct msghdr msghdr;
+ char m[SENDCMSGBUFLEN];
+ } cmsgbuf;
+
+ memset(&cmsgbuf, 0, sizeof(cmsgbuf));
+
+ build_msghdr_send(sock, cmsgbuf.m, dev, &msghdr, iov, &write_count);
resend:
cc = sendmsg(sock->fd, &msghdr, 0);