8220663: Incorrect handling of IPv6 addresses in Socket(Proxy.HTTP)

Reviewed-by: alanb, michaelm
This commit is contained in:
Chris Hegarty 2019-03-19 14:27:50 +00:00
parent 3b0ae8082a
commit 5ee0711360
2 changed files with 79 additions and 34 deletions

View file

@ -114,14 +114,17 @@ import java.util.Set;
if (endpoint == null || !(endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException("Unsupported address type");
final InetSocketAddress epoint = (InetSocketAddress)endpoint;
final String destHost = epoint.isUnresolved() ? epoint.getHostName()
: epoint.getAddress().getHostAddress();
String destHost = epoint.isUnresolved() ? epoint.getHostName()
: epoint.getAddress().getHostAddress();
final int destPort = epoint.getPort();
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkConnect(destHost, destPort);
if (destHost.contains(":"))
destHost = "[" + destHost + "]";
// Connect to the HTTP proxy server
String urlString = "http://" + destHost + ":" + destPort;
Socket httpSocket = privilegedDoTunnel(urlString, timeout);