# HG changeset patch # User michaelm # Date 1384990387 0 # Node ID a0b6e589546447e9b6da8c0df8ce820d7f3d7107 # Parent a147b2084bc397acd1c32d6c2c97993d2423cd4c 8028453: AsynchronousSocketChannel.connect() requires SocketPermission due to bind to local address (win) Reviewed-by: alanb, chegar diff -r a147b2084bc3 -r a0b6e5895464 src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java --- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Thu Oct 24 20:39:21 2013 +0100 +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Wed Nov 20 23:33:07 2013 +0000 @@ -31,6 +31,9 @@ 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 @@ } } + private void doPrivilegedBind(final SocketAddress sa) throws IOException { + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Void run() throws IOException { + bind(sa); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (IOException) e.getException(); + } + } + @Override Future implConnect(SocketAddress remote, A attachment, @@ -330,7 +346,12 @@ 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; }