summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2021-02-17 03:22:58 +0100
committerBruno Haible <bruno@clisp.org>2021-02-17 03:22:58 +0100
commit4d4fb2be2f17938658ade0da9006593f715853e8 (patch)
tree8cde286d85a738adfa8789059f82773d088e7ce5
parent4b5bc7fdd55da390f486bafa1e91ba93dd8d887f (diff)
downloadgnulib-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--ChangeLog6
-rw-r--r--lib/passfd.c14
2 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 000690dd55..44d5dd70d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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;
}

Return to:

Send suggestions and report system problems to the System administrator.