diff options
author | Bruno Haible <bruno@clisp.org> | 2021-02-17 03:22:58 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-02-17 03:22:58 +0100 |
commit | 4d4fb2be2f17938658ade0da9006593f715853e8 (patch) | |
tree | 8cde286d85a738adfa8789059f82773d088e7ce5 | |
parent | 4b5bc7fdd55da390f486bafa1e91ba93dd8d887f (diff) | |
download | gnulib-4d4fb2be2f17938658ade0da9006593f715853e8.tar.gz gnulib-4d4fb2be2f17938658ade0da9006593f715853e8.tar.bz2 |
passfd: Fix test failure on FreeBSD >= 12 and NetBSD in 64-bit mode.
* lib/passfd.c (recvfd): Use the CMSG_SPACE macro to compute the value
for msg_controllen.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/passfd.c | 14 |
2 files changed, 15 insertions, 5 deletions
@@ -1,3 +1,9 @@ +2021-02-16 Bruno Haible <bruno@clisp.org> + + passfd: Fix test failure on FreeBSD >= 12 and NetBSD in 64-bit mode. + * lib/passfd.c (recvfd): Use the CMSG_SPACE macro to compute the value + for msg_controllen. + 2021-02-16 Paul Eggert <eggert@cs.ucla.edu> Port better to macOS Mojave diff --git a/lib/passfd.c b/lib/passfd.c index ca10ba584b..a993f39537 100644 --- a/lib/passfd.c +++ b/lib/passfd.c @@ -142,19 +142,23 @@ recvfd (int sock, int flags) cmsg->cmsg_len = CMSG_LEN (sizeof fd); /* Initialize the payload: */ memcpy (CMSG_DATA (cmsg), &fd, sizeof fd); - msg.msg_controllen = cmsg->cmsg_len; + msg.msg_controllen = CMSG_SPACE (sizeof fd); len = recvmsg (sock, &msg, flags_recvmsg); if (len < 0) return -1; - + if (len == 0) + { + /* fake errno: at end the file is not available */ + errno = ENOTCONN; + return -1; + } cmsg = CMSG_FIRSTHDR (&msg); /* be paranoiac */ - if (len == 0 || cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd) + if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd) || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { - /* fake errno: at end the file is not available */ - errno = len ? EACCES : ENOTCONN; + errno = EACCES; return -1; } |