提交 0ef74b41 编写于 作者: M michaelm

8028453: AsynchronousSocketChannel.connect() requires SocketPermission due to...

8028453: AsynchronousSocketChannel.connect() requires SocketPermission due to bind to local address (win)
Reviewed-by: alanb, chegar
上级 88c53b88
...@@ -31,6 +31,9 @@ import java.nio.BufferOverflowException; ...@@ -31,6 +31,9 @@ import java.nio.BufferOverflowException;
import java.net.*; import java.net.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import sun.misc.Unsafe; import sun.misc.Unsafe;
/** /**
...@@ -300,6 +303,19 @@ class WindowsAsynchronousSocketChannelImpl ...@@ -300,6 +303,19 @@ class WindowsAsynchronousSocketChannelImpl
} }
} }
private void doPrivilegedBind(final SocketAddress sa) throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
bind(sa);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
@Override @Override
<A> Future<Void> implConnect(SocketAddress remote, <A> Future<Void> implConnect(SocketAddress remote,
A attachment, A attachment,
...@@ -330,7 +346,12 @@ class WindowsAsynchronousSocketChannelImpl ...@@ -330,7 +346,12 @@ class WindowsAsynchronousSocketChannelImpl
throw new ConnectionPendingException(); throw new ConnectionPendingException();
if (localAddress == null) { if (localAddress == null) {
try { try {
bind(new InetSocketAddress(0)); SocketAddress any = new InetSocketAddress(0);
if (sm == null) {
bind(any);
} else {
doPrivilegedBind(any);
}
} catch (IOException x) { } catch (IOException x) {
bindException = x; bindException = x;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册