util: allow for a maximum of 32 fds in xsend_with_fds

Our current maximum of fds per the protocol is exactly 1 so this has
no effect but might save us in the future from some naughty client.
Meanwhile, this prevents us from having a variable-length array on the
stack that is caller-controller.

Assisted-by: Claude:claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/388>
This commit is contained in:
Peter Hutterer 2026-04-18 09:13:06 +10:00 committed by Marge Bot
parent 1b4a0d7c1a
commit f63b44d8ae

View file

@ -88,6 +88,11 @@ xsend_with_fd(int fd, const void *buf, size_t len, int *fds)
if (nfds == 0)
return xsend(fd, buf, len);
const size_t MAX_FDS = 32;
if (nfds > MAX_FDS) {
return -EINVAL;
}
char control[CMSG_SPACE(nfds * sizeof(int))];
struct cmsghdr *header = (struct cmsghdr *)control;