--- src/core/manager.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/core/manager.c b/src/core/manager.c index 634b141..74fb52d 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1275,9 +1275,10 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t }; union { - struct cmsghdr cmsghdr; + struct msghdr msghdr; uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; } control = {}; + struct cmsghdr *cmsghdr; struct msghdr msghdr = { .msg_iov = &iovec, @@ -1285,7 +1286,7 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t .msg_control = &control, .msg_controllen = sizeof(control), }; - struct ucred *ucred; + struct ucred *ucred = NULL; Unit *u; _cleanup_strv_free_ char **tags = NULL; @@ -1300,15 +1301,27 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t return -errno; } - if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) || - control.cmsghdr.cmsg_level != SOL_SOCKET || - control.cmsghdr.cmsg_type != SCM_CREDENTIALS || - control.cmsghdr.cmsg_len != CMSG_LEN(sizeof(struct ucred))) { - log_warning("Received notify message without credentials. Ignoring."); + if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct cmsghdr))) { + log_warning("sd_notify ancilliary message too short."); continue; } - ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr); + cmsghdr = CMSG_FIRSTHDR(&control.msghdr); + do { + if (cmsghdr->cmsg_level == SOL_SOCKET && + cmsghdr->cmsg_type == SCM_CREDENTIALS && + cmsghdr->cmsg_len == CMSG_LEN(sizeof(struct ucred))) + ucred = (struct ucred*) CMSG_DATA(cmsghdr); + else { + log_warning("Unrecognized sd_notify ancilliary message. Ignoring"); + continue; + } + } while ((cmsghdr = CMSG_NXTHDR(&control.msghdr, cmsghdr))); + + if (!ucred) { + log_warning("Received notify message without credentials. Ignoring."); + continue; + } u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid)); if (!u) { -- 1.8.5.2.297.g3e57c29 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel