about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2023-02-09 14:50:49 -0800
committerRich Felker <dalias@aerifal.cx>2023-02-12 17:38:37 -0500
commitf79b973d92a322800b3e8411ccc95db280d997ae (patch)
tree79452ad4169d2c144fa236241879750c41911d33 /src
parent0ab97350f01b42de0f9fd811ee08653169661859 (diff)
downloadmusl-f79b973d92a322800b3e8411ccc95db280d997ae.tar.gz
musl-f79b973d92a322800b3e8411ccc95db280d997ae.tar.xz
musl-f79b973d92a322800b3e8411ccc95db280d997ae.zip
increase sendmsg internal buffer to support SCM_MAX_FD
The kernel defines a limit on the number of fds that can be passed
through an SCM_RIGHTS ancillary message as SCM_MAX_FD. The value was
255 before kernel 2.6.38 (after that it is 253), and an SCM_RIGHTS
ancillary message with 255 fds requires 1040 bytes, slightly more than
the current 1024 byte internal buffer in sendmsg. 1024 is an arbitrary
size, so increase it to match the the arbitrary size limit in the
kernel. This fixes tests that are verifying they support up to
SCM_MAX_FD fds.
Diffstat (limited to 'src')
-rw-r--r--src/network/sendmsg.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/network/sendmsg.c b/src/network/sendmsg.c
index 80cc5f41..acdfdf29 100644
--- a/src/network/sendmsg.c
+++ b/src/network/sendmsg.c
@@ -8,13 +8,16 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
 {
 #if LONG_MAX > INT_MAX
 	struct msghdr h;
-	struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c;
+	/* Kernels before 2.6.38 set SCM_MAX_FD to 255, allocate enough
+	 * space to support an SCM_RIGHTS ancillary message with 255 fds.
+	 * Kernels since 2.6.38 set SCM_MAX_FD to 253. */
+	struct cmsghdr chbuf[CMSG_SPACE(255*sizeof(int))/sizeof(struct cmsghdr)+1], *c;
 	if (msg) {
 		h = *msg;
 		h.__pad1 = h.__pad2 = 0;
 		msg = &h;
 		if (h.msg_controllen) {
-			if (h.msg_controllen > 1024) {
+			if (h.msg_controllen > sizeof chbuf) {
 				errno = ENOMEM;
 				return -1;
 			}