From ae7f27e2521ca5e32d282c3f874a8389eee05d22 Mon Sep 17 00:00:00 2001 From: michaelm Date: Wed, 20 Nov 2013 23:33:07 +0000 Subject: [PATCH] 8028453: AsynchronousSocketChannel.connect() requires SocketPermission due to bind to local address (win) Reviewed-by: alanb, chegar --- .../WindowsAsynchronousSocketChannelImpl.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java index 124205a65..8e193a888 100644 --- a/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java +++ b/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java @@ -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() { + 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 @@ 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; } -- GitLab