提交 baba77a8 编写于 作者: J jccollet

6801497: Proxy is assumed to be immutable but is non-final

Summary: Cloned the proxy instance when necessary
Reviewed-by: chegar
上级 0601dadc
...@@ -114,9 +114,14 @@ class Socket implements java.io.Closeable { ...@@ -114,9 +114,14 @@ class Socket implements java.io.Closeable {
* @since 1.5 * @since 1.5
*/ */
public Socket(Proxy proxy) { public Socket(Proxy proxy) {
if (proxy != null && proxy.type() == Proxy.Type.SOCKS) { // Create a copy of Proxy as a security measure
if (proxy == null) {
throw new IllegalArgumentException("Invalid Proxy");
}
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : new Proxy(proxy.type(), proxy.address());
if (p.type() == Proxy.Type.SOCKS) {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) proxy.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();
if (security != null) { if (security != null) {
if (epoint.isUnresolved()) if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(), security.checkConnect(epoint.getHostName(),
...@@ -125,10 +130,10 @@ class Socket implements java.io.Closeable { ...@@ -125,10 +130,10 @@ class Socket implements java.io.Closeable {
security.checkConnect(epoint.getAddress().getHostAddress(), security.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort()); epoint.getPort());
} }
impl = new SocksSocketImpl(proxy); impl = new SocksSocketImpl(p);
impl.setSocket(this); impl.setSocket(this);
} else { } else {
if (proxy == Proxy.NO_PROXY) { if (p == Proxy.NO_PROXY) {
if (factory == null) { if (factory == null) {
impl = new PlainSocketImpl(); impl = new PlainSocketImpl();
impl.setSocket(this); impl.setSocket(this);
......
...@@ -1004,16 +1004,18 @@ public final class URL implements java.io.Serializable { ...@@ -1004,16 +1004,18 @@ public final class URL implements java.io.Serializable {
throw new IllegalArgumentException("proxy can not be null"); throw new IllegalArgumentException("proxy can not be null");
} }
// Create a copy of Proxy as a security measure
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : new Proxy(proxy.type(), proxy.address());
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (proxy.type() != Proxy.Type.DIRECT && sm != null) { if (p.type() != Proxy.Type.DIRECT && sm != null) {
InetSocketAddress epoint = (InetSocketAddress) proxy.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();
if (epoint.isUnresolved()) if (epoint.isUnresolved())
sm.checkConnect(epoint.getHostName(), epoint.getPort()); sm.checkConnect(epoint.getHostName(), epoint.getPort());
else else
sm.checkConnect(epoint.getAddress().getHostAddress(), sm.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort()); epoint.getPort());
} }
return handler.openConnection(this, proxy); return handler.openConnection(this, p);
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册