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