diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-11-19 11:16:04 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-11-19 11:16:04 +0100 |
commit | 07cd2298dcbf7da8db22d630cb84c0216da30ea1 (patch) | |
tree | b925618caa176010f67443159cc88f4d625bc42b /common | |
parent | 14263e17e425d1bca7e99d4ddfca1ace3bae0ca7 (diff) | |
download | tigervnc-07cd2298dcbf7da8db22d630cb84c0216da30ea1.tar.gz tigervnc-07cd2298dcbf7da8db22d630cb84c0216da30ea1.zip |
Protect IPv6 address strings with []
This is the format we support when converting a string to an
address, so it makes sense to use them the other way around.
Diffstat (limited to 'common')
-rw-r--r-- | common/network/TcpSocket.cxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index bbc41580..dd028600 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -249,17 +249,21 @@ char* TcpSocket::getPeerAddress() { #if defined(HAVE_GETADDRINFO) && defined(HAVE_INET_PTON) if (sa.u.sa.sa_family == AF_INET6) { - char buffer[INET6_ADDRSTRLEN]; + char buffer[INET6_ADDRSTRLEN + 2]; const char *name; + buffer[0] = '['; + name = inet_ntop(sa.u.sa.sa_family, &sa.u.sin6.sin6_addr, - buffer + 1, sizeof(buffer)); + buffer + 1, sizeof(buffer) - 2); if (name == NULL) { vlog.error("unable to convert peer name to a string"); return rfb::strDup(""); } - return rfb::strDup(name); + strcat(buffer, "]"); + + return rfb::strDup(buffer); } #endif |