From d3f474999f439870413b5eea33ce4d84157a833a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 7 Feb 2013 21:14:56 +0000 Subject: [PATCH] Escape environment-based D-Bus addresses properly If XDG_RUNTIME_DIR contains a character like ":" (for instance if it's formed from an X11 display name), then it isn't valid to substitute it into a D-Bus address without escaping. Signed-off-by: Simon McVittie --- src/core/dbus.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/core/dbus.c b/src/core/dbus.c index 2a1c660..08aff1f 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -1077,18 +1077,33 @@ static int bus_init_private(Manager *m) { } else { const char *e; char *p; + char *escaped; e = secure_getenv("XDG_RUNTIME_DIR"); if (!e) return 0; - if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) { + if (asprintf(&p, "%s/systemd/private", e) < 0) { r = log_oom(); goto fail; } - mkdir_parents_label(p+10, 0755); - unlink(p+10); + mkdir_parents_label(p, 0755); + unlink(p); + free(p); + + escaped = dbus_address_escape_value(e); + if (!escaped) { + r = log_oom(); + goto fail; + } + if (asprintf(&p, "unix:path=%s/systemd/private", escaped) < 0) { + dbus_free(escaped); + r = log_oom(); + goto fail; + } + dbus_free(escaped); + m->private_bus = dbus_server_listen(p, &error); free(p); } -- 1.7.10.4