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/import | |
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/import')
-rw-r--r-- | src/import/importd.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/import/importd.c b/src/import/importd.c index 79c2e45276..a0c40cc3d0 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -633,7 +633,7 @@ static Manager *manager_unref(Manager *m) { DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref); static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - + Manager *m = ASSERT_PTR(userdata); char buf[NOTIFY_BUFFER_MAX+1]; struct iovec iovec = { .iov_base = buf, @@ -647,33 +647,32 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void .msg_control = &control, .msg_controllen = sizeof(control), }; - struct ucred *ucred; - Manager *m = userdata; - Transfer *t; ssize_t n; - char *p; 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; - ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); + cmsg_close_all(&msghdr); + + struct ucred *ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); if (!ucred || ucred->pid <= 0) { log_warning("Got notification datagram lacking credential information, ignoring."); return 0; } + Transfer *t; HASHMAP_FOREACH(t, m->transfers) if (ucred->pid == t->pidref.pid) break; @@ -685,7 +684,7 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void buf[n] = 0; - p = find_line_startswith(buf, "X_IMPORT_PROGRESS="); + char *p = find_line_startswith(buf, "X_IMPORT_PROGRESS="); if (!p) return 0; |