From: Zbigniew Jędrzejewski-Szmek Date: Fri, 10 Apr 2026 21:18:10 +0000 (+0200) Subject: executor: do not abort on invalid serialization fd X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=56836138b0752c1704585a573e4b12dd28f70b9d;p=thirdparty%2Fsystemd.git executor: do not abort on invalid serialization fd E.g. --deserialize=15 would cause the program to abrt in safe_close. But in fact, we shouldn't try to do the close in any case: if the fd is not valid, we should return an error without modifying state. And if it _is_ valid, we set O_CLOEXEC on it, so it'll be closed automatically later. --- diff --git a/src/core/executor.c b/src/core/executor.c index 80d4d8c71ae..8089d376fe8 100644 --- a/src/core/executor.c +++ b/src/core/executor.c @@ -16,7 +16,6 @@ #include "exit-status.h" #include "fd-util.h" #include "fdset.h" -#include "fileio.h" #include "format-table.h" #include "label-util.h" #include "log.h" @@ -106,19 +105,19 @@ static int parse_argv(int argc, char *argv[]) { break; OPTION_LONG("deserialize", "FD", "Deserialize process config from FD"): { - _cleanup_close_ int fd = -EBADF; - FILE *f; - - fd = parse_fd(arg); + int fd = parse_fd(arg); if (fd < 0) return log_error_errno(fd, "Failed to parse serialization fd \"%s\": %m", arg); + /* Set O_CLOEXEC and as a side effect, verify that the fd is valid. */ r = fd_cloexec(fd, /* cloexec= */ true); + if (r == -EBADF) + return log_error_errno(r, "Serialization fd %d is not valid.", fd); if (r < 0) return log_error_errno(r, "Failed to set serialization fd %d to close-on-exec: %m", fd); - f = take_fdopen(&fd, "r"); + FILE *f = fdopen(fd, "r"); if (!f) return log_error_errno(errno, "Failed to open serialization fd %d: %m", fd);