ryantimwilson / rpms / systemd

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