From 86312d159d55e99db5a5c82d9c50f31a1fe28199 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 7 Dec 2020 18:28:04 +0000 Subject: Some trivial bugfixes and cleanups --- src/libunixonacid/ancil_recv_fd.c | 9 ++++++--- src/libunixonacid/ancil_send_fd.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/libunixonacid') diff --git a/src/libunixonacid/ancil_recv_fd.c b/src/libunixonacid/ancil_recv_fd.c index 70f2c4f..5ecbb31 100644 --- a/src/libunixonacid/ancil_recv_fd.c +++ b/src/libunixonacid/ancil_recv_fd.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -33,6 +34,7 @@ int ancil_recv_fd (int sock, char expected_ch) 0 #endif ; + int fd ; struct cmsghdr *c ; ssize_t r ; char ch ; @@ -58,12 +60,13 @@ int ancil_recv_fd (int sock, char expected_ch) || c->cmsg_level != SOL_SOCKET || c->cmsg_type != SCM_RIGHTS || (size_t)(c->cmsg_len - (CMSG_DATA(c) - (unsigned char *)c)) != sizeof(int)) return (errno = EPROTO, -1) ; + memcpy(&fd, CMSG_DATA(c), sizeof(int)) ; #ifndef SKALIBS_HASCMSGCLOEXEC - if (coe(*(int *)CMSG_DATA(c)) < 0) + if (coe(fd) < 0) { - fd_close(*(int *)CMSG_DATA(c)) ; + fd_close(fd) ; return -1 ; } #endif - return *(int *)CMSG_DATA(c) ; + return fd ; } diff --git a/src/libunixonacid/ancil_send_fd.c b/src/libunixonacid/ancil_send_fd.c index 939d06c..5573d5c 100644 --- a/src/libunixonacid/ancil_send_fd.c +++ b/src/libunixonacid/ancil_send_fd.c @@ -35,7 +35,7 @@ int ancil_send_fd (int sock, int fd, char ch) c->cmsg_level = SOL_SOCKET ; c->cmsg_type = SCM_RIGHTS ; c->cmsg_len = CMSG_LEN(sizeof(int)) ; - *(int *)CMSG_DATA(c) = fd ; + memcpy(CMSG_DATA(c), &fd, sizeof(int)) ; do r = sendmsg(sock, &hdr, MSG_NOSIGNAL) ; while (r < 0 && errno == EINTR) ; if (r <= 0) return 0 ; -- cgit v1.2.3