--- a/jdk/src/share/classes/java/net/Socket.java Tue Dec 01 08:55:15 2009 -0800
+++ b/jdk/src/share/classes/java/net/Socket.java Wed Dec 02 12:17:42 2009 +0000
@@ -122,6 +122,9 @@
if (p.type() == Proxy.Type.SOCKS) {
SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) p.address();
+ if (epoint.getAddress() != null) {
+ checkAddress (epoint.getAddress(), "Socket");
+ }
if (security != null) {
if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(),
@@ -558,15 +561,16 @@
throw new IllegalArgumentException("Unsupported address type");
InetSocketAddress epoint = (InetSocketAddress) endpoint;
+ InetAddress addr = epoint.getAddress ();
+ int port = epoint.getPort();
+ checkAddress(addr, "connect");
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (epoint.isUnresolved())
- security.checkConnect(epoint.getHostName(),
- epoint.getPort());
+ security.checkConnect(epoint.getHostName(), port);
else
- security.checkConnect(epoint.getAddress().getHostAddress(),
- epoint.getPort());
+ security.checkConnect(addr.getHostAddress(), port);
}
if (!created)
createImpl(true);
@@ -574,10 +578,9 @@
impl.connect(epoint, timeout);
else if (timeout == 0) {
if (epoint.isUnresolved())
- impl.connect(epoint.getAddress().getHostName(),
- epoint.getPort());
+ impl.connect(addr.getHostName(), port);
else
- impl.connect(epoint.getAddress(), epoint.getPort());
+ impl.connect(addr, port);
} else
throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)");
connected = true;
@@ -614,14 +617,25 @@
InetSocketAddress epoint = (InetSocketAddress) bindpoint;
if (epoint != null && epoint.isUnresolved())
throw new SocketException("Unresolved address");
- if (bindpoint == null)
- getImpl().bind(InetAddress.anyLocalAddress(), 0);
- else
- getImpl().bind(epoint.getAddress(),
- epoint.getPort());
+ if (epoint == null) {
+ epoint = new InetSocketAddress(0);
+ }
+ InetAddress addr = epoint.getAddress();
+ int port = epoint.getPort();
+ checkAddress (addr, "bind");
+ getImpl().bind (addr, port);
bound = true;
}
+ private void checkAddress (InetAddress addr, String op) {
+ if (addr == null) {
+ return;
+ }
+ if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) {
+ throw new IllegalArgumentException(op + ": invalid address type");
+ }
+ }
+
/**
* set the flags after an accept() call.
*/