]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
executor: do not abort on invalid serialization fd
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 10 Apr 2026 21:18:10 +0000 (23:18 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 14 Apr 2026 08:50:36 +0000 (10:50 +0200)
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.

src/core/executor.c

index 80d4d8c71ae44efb034140ca9dc528a8b2ae7e83..8089d376fe8305fe053fb6c6f6ef82b5cb9eadc4 100644 (file)
@@ -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);