[PATCH v2 2/2] qemu_dbus: Escape path to dbus-daemon socket if needed

Michal Privoznik via Devel posted 2 patches 2 weeks, 6 days ago
[PATCH v2 2/2] qemu_dbus: Escape path to dbus-daemon socket if needed
Posted by Michal Privoznik via Devel 2 weeks, 6 days ago
From: Michal Privoznik <mprivozn@redhat.com>

Inside of qemuDBusWriteConfig() the config file for dbus-daemon
is written. In it is path to the socket where the daemon should
listen to. But the path is derived from guest name and as such
may contain characters that DBus requires escaped (e.g. a space).
Use virStringEscapeDBus() to escape the path before writing it
into the config file.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/834
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_dbus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c
index 625884ad46..777facbcf4 100644
--- a/src/qemu/qemu_dbus.c
+++ b/src/qemu/qemu_dbus.c
@@ -25,6 +25,7 @@
 #include "virtime.h"
 #include "virpidfile.h"
 #include "virutil.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -119,6 +120,7 @@ static int
 qemuDBusWriteConfig(const char *filename, const char *path, bool privileged)
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autofree char *escapedPath = virStringEscapeDBus(path);
     g_autofree char *config = NULL;
 
     virBufferAddLit(&buf, "<!DOCTYPE busconfig PUBLIC \"-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN\"\n");
@@ -127,7 +129,7 @@ qemuDBusWriteConfig(const char *filename, const char *path, bool privileged)
     virBufferAdjustIndent(&buf, 2);
 
     virBufferAddLit(&buf, "<type>org.libvirt.qemu</type>\n");
-    virBufferAsprintf(&buf, "<listen>unix:path=%s</listen>\n", path);
+    virBufferAsprintf(&buf, "<listen>unix:path=%s</listen>\n", escapedPath);
     virBufferAddLit(&buf, "<auth>EXTERNAL</auth>\n");
 
     virBufferAddLit(&buf, "<policy context='default'>\n");
-- 
2.51.2