From d4f7fa5e33d020af9e60fc2963eb5ddd2e92dc61 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Wed, 20 Nov 2013 22:25:52 +0800 Subject: [PATCH v2] _dbus_append_address_from_socket(): escape value got from socket fd So far, this bug can be triggered in systemd environment, if the configured ListenStream for dbus.socket has characters must be escaped first. Then we'll get an error like "In D-Bus address, character '%c' should have been escaped\n" Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46013 --- dbus/dbus-sysdeps-unix.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 0708004..b82c2bc 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4050,6 +4050,7 @@ _dbus_append_address_from_socket (int fd, } socket; char hostip[INET6_ADDRSTRLEN]; int size = sizeof (socket); + DBusString path_str; if (getsockname (fd, &socket.sa, &size)) goto err; @@ -4059,26 +4060,32 @@ _dbus_append_address_from_socket (int fd, case AF_UNIX: if (socket.un.sun_path[0]=='\0') { - if (_dbus_string_append_printf (address, "unix:abstract=%s", &(socket.un.sun_path[1]))) + _dbus_string_init_const (&path_str, &(socket.un.sun_path[1])); + if (_dbus_string_append (address, "unix:abstract=") && + _dbus_address_append_escaped (address, &path_str)) return TRUE; } else { - if (_dbus_string_append_printf (address, "unix:path=%s", socket.un.sun_path)) + _dbus_string_init_const (&path_str, socket.un.sun_path); + if (_dbus_string_append (address, "unix:path=") && + _dbus_address_append_escaped (address, &path_str)) return TRUE; } break; case AF_INET: if (inet_ntop (AF_INET, &socket.ipv4.sin_addr, hostip, sizeof (hostip))) if (_dbus_string_append_printf (address, "tcp:family=ipv4,host=%s,port=%u", - hostip, ntohs (socket.ipv4.sin_port))) + hostip, ntohs (socket.ipv4.sin_port))) return TRUE; break; #ifdef AF_INET6 case AF_INET6: + _dbus_string_init_const (&path_str, hostip); if (inet_ntop (AF_INET6, &socket.ipv6.sin6_addr, hostip, sizeof (hostip))) - if (_dbus_string_append_printf (address, "tcp:family=ipv6,host=%s,port=%u", - hostip, ntohs (socket.ipv6.sin6_port))) + if (_dbus_string_append_printf (address, "tcp:family=ipv6,port=%u,host=", + ntohs (socket.ipv6.sin6_port)) && + _dbus_address_append_escaped (address, &path_str)) return TRUE; break; #endif -- 1.7.9.5