summaryrefslogtreecommitdiff
path: root/src/libunixonacid/ancil_recv_fd.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-12-07 18:28:04 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-12-07 18:28:04 +0000
commit86312d159d55e99db5a5c82d9c50f31a1fe28199 (patch)
tree0f9f94e6c6d223df2f4beb3247c96e510ff0804d /src/libunixonacid/ancil_recv_fd.c
parent2ddd93b4423b94578868e2701c265f8da4350965 (diff)
downloadskalibs-86312d159d55e99db5a5c82d9c50f31a1fe28199.tar.xz
Some trivial bugfixes and cleanups
Diffstat (limited to 'src/libunixonacid/ancil_recv_fd.c')
-rw-r--r--src/libunixonacid/ancil_recv_fd.c9
1 files changed, 6 insertions, 3 deletions
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 <skalibs/nonposix.h>
#include <errno.h>
+#include <string.h>
#include <sys/uio.h>
#include <sys/socket.h>
@@ -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 ;
}