richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 4e78db7126779a9f6432ead9a73cdab1087405bc Mon Sep 17 00:00:00 2001
923a60
From: Lukas Nykryn <lnykryn@redhat.com>
923a60
Date: Fri, 17 Apr 2015 15:12:00 +0200
923a60
Subject: [PATCH] machine: do not rely on asprintf setting arg on error
923a60
923a60
Strictly speaking, the output variable is undefined if asprintf fails.
923a60
We use the return value not the arg everywhere, and should we do here.
923a60
923a60
(Based on 2c07315225bef6be4830bce25a74da7f0ba4fcdc)
923a60
---
923a60
 src/machine/machine-dbus.c | 10 ++++++----
923a60
 1 file changed, 6 insertions(+), 4 deletions(-)
923a60
923a60
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
923a60
index b0f0f66e09..624a99f4e9 100644
923a60
--- a/src/machine/machine-dbus.c
923a60
+++ b/src/machine/machine-dbus.c
923a60
@@ -438,6 +438,7 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
923a60
         _cleanup_close_ int master = -1;
923a60
         Machine *m = userdata;
923a60
         const char *p;
923a60
+        char *address;
923a60
         int r;
923a60
 
923a60
         if (m->class != MACHINE_CONTAINER)
923a60
@@ -475,13 +476,14 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
923a60
                 return r;
923a60
 
923a60
 #ifdef ENABLE_KDBUS
923a60
-        asprintf(&container_bus->address, "x-machine-kernel:pid=" PID_FMT ";x-machine-unix:pid=" PID_FMT, m->leader, m->leader);
923a60
+#  define ADDRESS_FMT "x-machine-kernel:pid=%1$" PID_PRI ";x-machine-unix:pid=%1$" PID_PRI
923a60
 #else
923a60
-        asprintf(&container_bus->address, "x-machine-unix:pid=" PID_FMT, m->leader);
923a60
+#  define ADDRESS_FMT "x-machine-unix:pid=%1$" PID_PRI
923a60
 #endif
923a60
-        if (!container_bus->address)
923a60
-                return -ENOMEM;
923a60
+        if (asprintf(&address, ADDRESS_FMT, m->leader) < 0)
923a60
+                return log_oom();
923a60
 
923a60
+        container_bus->address = address;
923a60
         container_bus->bus_client = true;
923a60
         container_bus->trusted = false;
923a60
         container_bus->is_system = true;