diff --git a/src/libsystemd/sd-netlink/netlink-internal.h b/src/libsystemd/sd-netlink/netlink-internal.h index c214792147..c7d4cd70d4 100644 --- a/src/libsystemd/sd-netlink/netlink-internal.h +++ b/src/libsystemd/sd-netlink/netlink-internal.h @@ -128,6 +128,7 @@ typedef struct sd_netlink_message { bool sealed:1; sd_netlink_message *next; /* next in a chain of multi-part messages */ + sd_netlink_message *tail; /* last message in a multi-part chain */ } sd_netlink_message; int message_new_empty(sd_netlink *nl, sd_netlink_message **ret); diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 385d92a64f..113d999c1e 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -411,9 +411,11 @@ int socket_read_message(sd_netlink *nl) { if (existing) { /* This is the continuation of the previously read messages. * Let's append this message at the end. */ - while (existing->next) - existing = existing->next; - existing->next = TAKE_PTR(m); + if (existing->tail) + existing->tail->next = m; + else + existing->next = m; + existing->tail = TAKE_PTR(m); } else { /* This is the first message. Put it into the queue for partially * received messages. */