core/manager: fix (theoretical) fd leak on invalid messages

We'd leak fds on early return. We are sending a message to ourself,
so it's unlikely to fail. But let's keep the logic correct.

Reported by qarmin (Rafał Mikrut).
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-05-18 12:33:37 +02:00
parent e305f552ec
commit fd12cc9a52
+3
View File
@@ -5119,6 +5119,7 @@ static int manager_dispatch_pidref_transport_fd(sd_event_source *source, int fd,
if (n != sizeof(child_pid)) {
log_warning("Got pidref message of unexpected size %zi (expected %zu), ignoring.", n, sizeof(child_pid));
cmsg_close_all(&msghdr);
return 0;
}
@@ -5138,6 +5139,8 @@ static int manager_dispatch_pidref_transport_fd(sd_event_source *source, int fd,
}
}
/* From this point on, the fds are owned by our local variables. Call cmsg_close_all no more. */
/* Verify and set parent pidref. */
if (!ucred || !pid_is_valid(ucred->pid)) {
log_warning("Received pidref message without valid credentials. Ignoring.");