]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: do not try to use reply after freeing it (#3318)
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 21 May 2016 22:30:33 +0000 (18:30 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 21 May 2016 22:30:33 +0000 (18:30 -0400)
We'd call sd_bus_message_unref and then proceed to use
variables pointing into the reply buffer (fd and char*).
dup the fd and copy the string before destorying the reply.

This makes systemd-run run again for me.

https://bugzilla.redhat.com/show_bug.cgi?id=1337636

src/run/run.c

index 1d0f74ad219ba7a8b31da544be2dee4f14e6fb8d..d6c9b6d37a5c83d3f38a8f1606e1fdf32f442e8a 100644 (file)
@@ -760,6 +760,7 @@ static int start_transient_service(
 
                 } else if (arg_transport == BUS_TRANSPORT_MACHINE) {
                         _cleanup_(sd_bus_unrefp) sd_bus *system_bus = NULL;
+                        _cleanup_(sd_bus_message_unrefp) sd_bus_message *pty_reply = NULL;
                         const char *s;
 
                         r = sd_bus_default_system(&system_bus);
@@ -772,19 +773,17 @@ static int start_transient_service(
                                                "org.freedesktop.machine1.Manager",
                                                "OpenMachinePTY",
                                                &error,
-                                               &reply,
+                                               &pty_reply,
                                                "s", arg_host);
                         if (r < 0) {
                                 log_error("Failed to get machine PTY: %s", bus_error_message(&error, -r));
                                 return r;
                         }
 
-                        r = sd_bus_message_read(reply, "hs", &master, &s);
+                        r = sd_bus_message_read(pty_reply, "hs", &master, &s);
                         if (r < 0)
                                 return bus_log_parse_error(r);
 
-                        reply = sd_bus_message_unref(reply);
-
                         master = fcntl(master, F_DUPFD_CLOEXEC, 3);
                         if (master < 0)
                                 return log_error_errno(errno, "Failed to duplicate master fd: %m");