diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-08-31 00:17:13 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-09-04 18:51:44 +0200 |
commit | ad501930d749e00f9686d29692b3142c36914f31 (patch) | |
tree | 4829cbd3be34943b0f7b027decd813d2787be8e7 /src/sysupdate | |
parent | machine-dbus: use in_same_namespace() at one more place (diff) | |
download | systemd-ad501930d749e00f9686d29692b3142c36914f31.tar.xz systemd-ad501930d749e00f9686d29692b3142c36914f31.zip |
socket-util: make recvmsg_safe() handle MSG_TRUNC too
Also, unify MSG_TRUNC handling all across the codebase.
Diffstat (limited to 'src/sysupdate')
-rw-r--r-- | src/sysupdate/sysupdate-transfer.c | 20 | ||||
-rw-r--r-- | src/sysupdate/sysupdated.c | 22 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c index 7ea168961e..cbf3f77f5b 100644 --- a/src/sysupdate/sysupdate-transfer.c +++ b/src/sysupdate/sysupdate-transfer.c @@ -938,18 +938,20 @@ static int helper_on_notify(sd_event_source *s, int fd, uint32_t revents, void * int r; n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (n < 0) { - if (ERRNO_IS_TRANSIENT(n)) - return 0; - return (int) n; + if (ERRNO_IS_NEG_TRANSIENT(n)) + return 0; + if (n == -ECHRNG) { + log_warning_errno(n, "Got message with truncated control data (unexpected fds sent?), ignoring."); + return 0; } - - cmsg_close_all(&msghdr); - - if (msghdr.msg_flags & MSG_TRUNC) { - log_warning("Got overly long notification datagram, ignoring."); + if (n == -EXFULL) { + log_warning_errno(n, "Got message with truncated payload data, ignoring."); return 0; } + if (n < 0) + return (int) n; + + cmsg_close_all(&msghdr); ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); if (!ucred || ucred->pid <= 0) { diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index 6f15177c94..546f52a96c 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -419,7 +419,7 @@ static int job_start(Job *j) { if (IN_SET(j->type, JOB_UPDATE, JOB_VACUUM) && j->target->busy) return log_notice_errno(SYNTHETIC_ERRNO(EBUSY), "Target %s busy, ignoring job.", j->target->name); - + stdout_fd = memfd_new("sysupdate-stdout"); if (stdout_fd < 0) return log_error_errno(stdout_fd, "Failed to create memfd: %m"); @@ -1460,18 +1460,20 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void char *version, *progress, *errno_str, *ready; n = recvmsg_safe(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); - if (n < 0) { - if (ERRNO_IS_TRANSIENT(n)) - return 0; - return (int) n; + if (ERRNO_IS_NEG_TRANSIENT(n)) + return 0; + if (n == -ECHRNG) { + log_warning_errno(n, "Got message with truncated control data (unexpected fds sent?), ignoring."); + return 0; } - - cmsg_close_all(&msghdr); - - if (msghdr.msg_flags & MSG_TRUNC) { - log_warning("Got overly long notification datagram, ignoring."); + if (n == -EXFULL) { + log_warning_errno(n, "Got message with truncated payload data, ignoring."); return 0; } + if (n < 0) + return (int) n; + + cmsg_close_all(&msghdr); ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); if (!ucred || ucred->pid <= 0) { |