mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-07 21:48:41 +00:00
8028453: AsynchronousSocketChannel.connect() requires SocketPermission due to bind to local address (win)
Reviewed-by: alanb, chegar
This commit is contained in:
parent
bf39f5917a
commit
c7e80c8f2f
@ -31,6 +31,9 @@ import java.nio.BufferOverflowException;
|
||||
import java.net.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
/**
|
||||
@ -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
|
||||
<A> Future<Void> implConnect(SocketAddress remote,
|
||||
A attachment,
|
||||
@ -330,7 +346,12 @@ class WindowsAsynchronousSocketChannelImpl
|
||||
throw new ConnectionPendingException();
|
||||
if (localAddress == null) {
|
||||
try {
|
||||
bind(new InetSocketAddress(0));
|
||||
SocketAddress any = new InetSocketAddress(0);
|
||||
if (sm == null) {
|
||||
bind(any);
|
||||
} else {
|
||||
doPrivilegedBind(any);
|
||||
}
|
||||
} catch (IOException x) {
|
||||
bindException = x;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user