Commit 1d85b229 authored by Simon McVittie's avatar Simon McVittie

_dbus_append_address_from_socket: Make control flow clearer

In the current implementation, we can reach the "err" label either
because we ran out of memory, or because we got a socket error from
getsockname() or inet_ntop(), and we blindly assume that running out
of memory will set ENOMEM.

However, that isn't actually true: when we are simulating OOM in
dbus_malloc(), the fake OOM doesn't set ENOMEM. Handle the OOM
condition explicitly instead.

In the AF_UNIX case, the break statement is no longer reached at all,
so leave a comment there. In the AF_INET and AF_INET6 cases, if
inet_ntop() fails, explicitly goto err instead of using break
(this has the same practical effect) to make it clearer that we are
going to the "socket error" code path.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61922
parent 8a4e0792
......@@ -4674,31 +4674,64 @@ _dbus_append_address_from_socket (DBusSocket fd,
_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;
{
return TRUE;
}
else
{
_DBUS_SET_OOM (error);
return FALSE;
}
}
else
{
_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;
{
return TRUE;
}
else
{
_DBUS_SET_OOM (error);
return FALSE;
}
}
/* not reached */
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)))
return TRUE;
break;
{
if (_dbus_string_append_printf (address, "tcp:family=ipv4,host=%s,port=%u",
hostip, ntohs (socket.ipv4.sin_port)))
{
return TRUE;
}
else
{
_DBUS_SET_OOM (error);
return FALSE;
}
}
goto err;
#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,port=%u,host=",
ntohs (socket.ipv6.sin6_port)) &&
_dbus_address_append_escaped (address, &path_str))
return TRUE;
break;
{
if (_dbus_string_append_printf (address, "tcp:family=ipv6,port=%u,host=",
ntohs (socket.ipv6.sin6_port)) &&
_dbus_address_append_escaped (address, &path_str))
else
{
_DBUS_SET_OOM (error);
return FALSE;
}
}
goto err;
#endif
default:
dbus_set_error (error,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment