Blob Blame History Raw
From 6bd2824d07a7cdb622df9a7876185142ad1f48e1 Mon Sep 17 00:00:00 2001
From: Tom Gundersen <teg@jklm.no>
Date: Wed, 30 Aug 2017 13:09:03 +0200
Subject: [PATCH] sd-bus: socket - only transmit auxillary FDs once (#6603)

If a message is too large to fit into the output buffer, it will be
transmitted to the kernel in several chunks. However, the FDs must
only ever be transmitted once or they will bereceived by the remote
end repeatedly.

The D-Bus specification disallows several sets of FDs attached to
one message, however, the reference implementation of D-Bus will
not reject such a message, rather it will reassign the duplicate
FDs to subsequent FD-carrying messages.

This attaches the FD array only to the first byte of the message.

(cherry picked from commit f29eef2e9072eac6f6570ff7975680bc9caeda2f)
---
 src/libsystemd/sd-bus/bus-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 8b25002f01..ab70a0c6e1 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -800,7 +800,7 @@ int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
                         .msg_iovlen = m->n_iovec,
                 };
 
-                if (m->n_fds > 0) {
+                if (m->n_fds > 0 && *idx == 0) {
                         struct cmsghdr *control;
 
                         mh.msg_control = control = alloca(CMSG_SPACE(sizeof(int) * m->n_fds));