]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: allocate the buffer for varlink FDs on the heap
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 2 Aug 2023 12:55:50 +0000 (14:55 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 2 Aug 2023 21:03:46 +0000 (22:03 +0100)
Since it's ~16K, which might cause issues in environments with limited
stack space.

Resolves: #28635

src/shared/varlink.c

index 343f8b4aaca9ae10c340cc734354de7bea86168e..9bf9c4b5ac2e4b1abb065db36f4ad77063155af9 100644 (file)
@@ -633,7 +633,7 @@ static int varlink_write(Varlink *v) {
 #define VARLINK_FDS_MAX (16U*1024U)
 
 static int varlink_read(Varlink *v) {
-        CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(int) * VARLINK_FDS_MAX)) control;
+        _cleanup_free_ struct cmsghdr *cmsg_fds = NULL;
         struct iovec iov;
         struct msghdr mh;
         size_t rs;
@@ -690,9 +690,13 @@ static int varlink_read(Varlink *v) {
                 mh = (struct msghdr) {
                         .msg_iov = &iov,
                         .msg_iovlen = 1,
-                        .msg_control = &control,
-                        .msg_controllen = sizeof(control),
                 };
+
+                mh.msg_controllen = CMSG_SPACE(sizeof(int) * VARLINK_FDS_MAX);
+                mh.msg_control = cmsg_fds = malloc(mh.msg_controllen);
+                if (!cmsg_fds)
+                        return -ENOMEM;
+
                 n = recvmsg_safe(v->fd, &mh, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
         } else {
                 bool prefer_read = v->prefer_read_write;