diff options
author | Chengwei Yang <chengwei.yang@intel.com> | 2013-11-20 22:25:52 +0800 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-11-27 16:09:58 +0000 |
commit | 87f37d6d9860f3afe1a7b63cd5ba1411b817f5c0 (patch) | |
tree | 43d872a89236691d05ec52db6ebe2e6f78512052 | |
parent | 8c388a5d213aa28f5d92a19150a697c5eba5554f (diff) | |
download | dbus-87f37d6d9860f3afe1a7b63cd5ba1411b817f5c0.tar.gz |
_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
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 07080045..b82c2bc7 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 |