From c1227068bcadf761e30b845f73179e3d5391dacb Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 19 Jul 2010 13:05:29 +0200 Subject: [PATCH] Verify that getsockname succeeded in _dbus_listen_tcp_socket --- dbus/dbus-sysdeps-unix.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 46ac4d8..f1ec5e9 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1388,16 +1388,18 @@ _dbus_listen_tcp_socket (const char *host, to use the same port */ if (!port || !strcmp(port, "0")) { + int result; struct sockaddr_storage addr; socklen_t addrlen; char portbuf[50]; addrlen = sizeof(addr); - getsockname(fd, (struct sockaddr*) &addr, &addrlen); + result = getsockname(fd, (struct sockaddr*) &addr, &addrlen); - if ((res = getnameinfo((struct sockaddr*)&addr, addrlen, NULL, 0, - portbuf, sizeof(portbuf), - NI_NUMERICHOST)) != 0) + if (result == -1 || + (res = getnameinfo ((struct sockaddr*)&addr, addrlen, NULL, 0, + portbuf, sizeof(portbuf), + NI_NUMERICHOST)) != 0) { dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to resolve port \"%s:%s\": %s (%s)", -- 1.7.2.3