JDK-8220663 : Incorrect handling of IPv6 addresses in Socket(Proxy.HTTP)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 13
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-03-14
  • Updated: 2021-10-19
  • Resolved: 2019-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b13Fixed
Related Reports
Relates :  
Description
jshell> byte[] bytes = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
bytes ==> byte[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }

jshell> var proxyAddress = new InetSocketAddress(InetAddress.getByAddress(bytes), 8888)
proxyAddress ==> /0:0:0:0:0:0:0:1:8888

jshell> var endpointAddress = new InetSocketAddress(InetAddress.getByAddress(bytes), 9999)
endpointAddress ==> /0:0:0:0:0:0:0:1:9999

jshell> var proxy = new Proxy(Proxy.Type.HTTP, proxyAddress)
proxy ==> HTTP @ /0:0:0:0:0:0:0:1:8888

jshell> var socket = new Socket(proxy)
socket ==> Socket[unconnected]

jshell> socket.connect(endpointAddress)
|  Exception java.net.MalformedURLException: Error at index 1 in: "0:0:0:0:0:0:1:9999"
|        at URL.<init> (URL.java:684)
|        at URL.<init> (URL.java:546)
|        at URL.<init> (URL.java:493)
|        at HttpConnectSocketImpl.doTunnel (HttpConnectSocketImpl.java:163)
|        at HttpConnectSocketImpl$2.run (HttpConnectSocketImpl.java:151)
|        at HttpConnectSocketImpl$2.run (HttpConnectSocketImpl.java:149)
|        at AccessController.doPrivileged (AccessController.java:553)
|        at HttpConnectSocketImpl.privilegedDoTunnel (HttpConnectSocketImpl.java:148)
|        at HttpConnectSocketImpl.connect (HttpConnectSocketImpl.java:111)
|        at Socket.connect (Socket.java:589)
|        at Socket.connect (Socket.java:538)
|        at (#6:1)
|  Caused by: java.lang.NumberFormatException: Error at index 1 in: "0:0:0:0:0:0:1:9999"
|        at NumberFormatException.forCharSequence (NumberFormatException.java:84)
|        at Integer.parseInt (Integer.java:741)
|        at URLStreamHandler.parseURL (URLStreamHandler.java:223)
|        at URL.<init> (URL.java:679)
|        ...

Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/791052cc88db User: chegar Date: 2019-03-19 14:29:05 +0000
19-03-2019

IPv6 address strings should be enclosed in square brackets. Possibly: diff --git a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java --- a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java +++ b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java @@ -98,8 +98,8 @@ 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(); @@ -107,6 +107,8 @@ security.checkConnect(destHost, destPort); // Connect to the HTTP proxy server + if (destHost.contains(":")) + destHost = "[" + destHost + "]"; String urlString = "http://" + destHost + ":" + destPort; Socket httpSocket = privilegedDoTunnel(urlString, timeout);
14-03-2019