8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")

Reviewed-by: dfuchs, alanb
This commit is contained in:
Alan Bateman 2019-05-03 19:42:28 +01:00 committed by Aleksei Efimov
parent 566110929b
commit e91c1ec7a6
2 changed files with 16 additions and 4 deletions

View file

@ -37,6 +37,9 @@ import java.net.StandardSocketOptions;
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -59,7 +62,12 @@ class ServerSocketAdaptor // package-private
private volatile int timeout;
static ServerSocket create(ServerSocketChannelImpl ssc) {
return new ServerSocketAdaptor(ssc);
PrivilegedExceptionAction<ServerSocket> pa = () -> new ServerSocketAdaptor(ssc);
try {
return AccessController.doPrivileged(pa);
} catch (PrivilegedActionException pae) {
throw new InternalError("Should not reach here", pae);
}
}
private ServerSocketAdaptor(ServerSocketChannelImpl ssc) {

View file

@ -36,6 +36,9 @@ import java.net.SocketException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -61,10 +64,11 @@ class SocketAdaptor
}
static Socket create(SocketChannelImpl sc) {
PrivilegedExceptionAction<Socket> pa = () -> new SocketAdaptor(sc);
try {
return new SocketAdaptor(sc);
} catch (SocketException e) {
throw new InternalError("Should not reach here");
return AccessController.doPrivileged(pa);
} catch (PrivilegedActionException pae) {
throw new InternalError("Should not reach here", pae);
}
}