From 08ff37d05a04a1ceed6086cfceae9c34331cb633 Mon Sep 17 00:00:00 2001 From: Andreas Fett Date: Mon, 22 Oct 2018 22:03:22 +0200 Subject: [PATCH] os/xdmcp: Fix binding of ipv6 source address Choose the socket fd of the correct address family based on the address family of the argument to the -from option. Fixes: xorg/xserver#4 --- os/xdmcp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/os/xdmcp.c b/os/xdmcp.c index 62adead84..df3312df6 100644 --- a/os/xdmcp.c +++ b/os/xdmcp.c @@ -912,6 +912,7 @@ static void get_xdmcp_sock(void) { int soopts = 1; + int socketfd = -1; #if defined(IPv6) && defined(AF_INET6) if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) @@ -924,8 +925,18 @@ get_xdmcp_sock(void) sizeof(soopts)) < 0) XdmcpWarning("UDP set broadcast socket-option failed"); #endif /* SO_BROADCAST */ - if (xdmcpSocket >= 0 && xdm_from != NULL) { - if (bind(xdmcpSocket, (struct sockaddr *) &FromAddress, + + if (xdm_from == NULL) + return; + + if (SOCKADDR_FAMILY(FromAddress) == AF_INET) + socketfd = xdmcpSocket; +#if defined(IPv6) && defined(AF_INET6) + else if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + if (socketfd >= 0) { + if (bind(socketfd, (struct sockaddr *) &FromAddress, FromAddressLen) < 0) { FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from);