diff options
author | Adam Tkac <atkac@redhat.com> | 2009-11-12 10:32:43 +0000 |
---|---|---|
committer | Adam Tkac <atkac@redhat.com> | 2009-11-12 10:32:43 +0000 |
commit | 897814feb469b609c690cea8f7ce7687df4142ae (patch) | |
tree | 809674cc051e1cd2e6cc5aab8c56f36409b90f48 /common/network | |
parent | c9cda3b144b99af172b8b9f8a679fa0203c79ebd (diff) | |
download | tigervnc-897814feb469b609c690cea8f7ce7687df4142ae.tar.gz tigervnc-897814feb469b609c690cea8f7ce7687df4142ae.zip |
[Bugfix] Fix crash in TcpSocket::sameMachine for IPv6 connections (alan dot coopersmith at sun dot com)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3918 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common/network')
-rw-r--r-- | common/network/TcpSocket.cxx | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 7fd9c6ab..93cdceb2 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -293,13 +293,27 @@ char* TcpSocket::getPeerEndpoint() { } bool TcpSocket::sameMachine() { - struct sockaddr_in peeraddr, myaddr; - socklen_t addrlen = sizeof(struct sockaddr_in); + vnc_sockaddr_t peeraddr, myaddr; + socklen_t addrlen; - getpeername(getFd(), (struct sockaddr *)&peeraddr, &addrlen); - getsockname(getFd(), (struct sockaddr *)&myaddr, &addrlen); + addrlen = sizeof(peeraddr); + if (getpeername(getFd(), &peeraddr.u.sa, &addrlen) < 0) + throw SocketException ("unable to get peer address", errorNumber); - return (peeraddr.sin_addr.s_addr == myaddr.sin_addr.s_addr); + addrlen = sizeof(myaddr); /* need to reset, since getpeername overwrote */ + if (getsockname(getFd(), &myaddr.u.sa, &addrlen) < 0) + throw SocketException ("unable to get my address", errorNumber); + + if (peeraddr.u.sa.sa_family != myaddr.u.sa.sa_family) + return false; + +#ifdef HAVE_GETADDRINFO + if (peeraddr.u.sa.sa_family == AF_INET6) + return IN6_ARE_ADDR_EQUAL(&peeraddr.u.sin6.sin6_addr, + &myaddr.u.sin6.sin6_addr); +#endif + + return (peeraddr.u.sin.sin_addr.s_addr == myaddr.u.sin.sin_addr.s_addr); } void TcpSocket::shutdown() |