8274883: (se) Selector.open throws IAE when the default file system provider is changed to a custom provider

Reviewed-by: alanb, michaelm
This commit is contained in:
Maxim Kartashev 2021-12-07 16:59:34 +00:00 committed by Michael McMahon
parent 7ea4b19f54
commit 7217cb7878
4 changed files with 256 additions and 5 deletions

View file

@ -700,11 +700,11 @@ class SocketChannelImpl
private SocketAddress unixBind(SocketAddress local) throws IOException {
UnixDomainSockets.checkPermission();
if (local == null) {
return UnixDomainSockets.UNNAMED;
return UnixDomainSockets.unnamed();
} else {
Path path = UnixDomainSockets.checkAddress(local).getPath();
if (path.toString().isEmpty()) {
return UnixDomainSockets.UNNAMED;
return UnixDomainSockets.unnamed();
} else {
// bind to non-empty path
UnixDomainSockets.bind(fd, path);

View file

@ -44,7 +44,9 @@ import sun.nio.fs.AbstractFileSystemProvider;
class UnixDomainSockets {
private UnixDomainSockets() { }
static final UnixDomainSocketAddress UNNAMED = UnixDomainSocketAddress.of("");
private static class UnnamedHolder {
static final UnixDomainSocketAddress UNNAMED = UnixDomainSocketAddress.of("");
}
private static final boolean supported;
@ -71,7 +73,7 @@ class UnixDomainSockets {
// Security check passed
} catch (SecurityException e) {
// Return unnamed address only if security check fails
addr = UNNAMED;
addr = unnamed();
}
return addr;
}
@ -133,7 +135,11 @@ class UnixDomainSockets {
throw new BindException("Could not locate temporary directory for sockets");
int rnd = random.nextInt(Integer.MAX_VALUE);
try {
Path path = Path.of(dir, "socket_" + rnd);
final Path path = Path.of(dir, "socket_" + rnd);
if (path.getFileSystem().provider() != sun.nio.fs.DefaultFileSystemProvider.instance()) {
throw new UnsupportedOperationException(
"Unix Domain Sockets not supported on non-default file system");
}
return UnixDomainSocketAddress.of(path);
} catch (InvalidPathException e) {
throw new BindException("Invalid temporary directory");
@ -160,6 +166,10 @@ class UnixDomainSockets {
return n;
}
static UnixDomainSocketAddress unnamed() {
return UnnamedHolder.UNNAMED;
}
private static native boolean init();
private static native int socket0() throws IOException;