Author: peter_firmstone Date: Fri Nov 27 05:14:01 2015 New Revision: 1716790
URL: http://svn.apache.org/viewvc?rev=1716790&view=rev Log: Fix regression in TcpServerEndpoint as identified in jtreg test net/jini/jeri/tcp/localHostExposure/LocalHostExposure.java Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/net/jini/jeri/tcp/TcpServerEndpoint.java Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/net/jini/jeri/tcp/TcpServerEndpoint.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/net/jini/jeri/tcp/TcpServerEndpoint.java?rev=1716790&r1=1716789&r2=1716790&view=diff ============================================================================== --- river/jtsk/skunk/qa-refactor-namespace/trunk/src/net/jini/jeri/tcp/TcpServerEndpoint.java (original) +++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/net/jini/jeri/tcp/TcpServerEndpoint.java Fri Nov 27 05:14:01 2015 @@ -32,11 +32,13 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.net.SocketPermission; import java.net.UnknownHostException; import java.nio.channels.SocketChannel; import java.nio.channels.ServerSocketChannel; import java.security.AccessControlContext; import java.security.AccessController; +import java.security.Guard; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -132,6 +134,7 @@ public final class TcpServerEndpoint imp private static final InetAddress localAdd; private static final UnknownHostException exception; + private static final Guard exposeLocalAdd; static { /* The following was originally in @@ -152,23 +155,16 @@ public final class TcpServerEndpoint imp } }); } catch (PrivilegedActionException e) { - try { - /* - * Only expose UnknownHostException thrown directly by - * InetAddress.getLocalHost if it would also be thrown - * in the caller's security context; otherwise, throw - * a new UnknownHostException without the host name. - */ - InetAddress.getLocalHost(); - } catch (UnknownHostException ex) { - exc = ex; + Exception uhe = e.getException(); + if (uhe instanceof UnknownHostException){ + exc = (UnknownHostException) uhe; } - if (exc == null) - exc = new UnknownHostException("access to resolve local host denied"); } localAdd = localAddr; exception = exc; + // If exception occurs the localAdd will be null. + exposeLocalAdd = new SocketPermission("localhost", "resolve"); } /** name for local host to fill in to corresponding TcpEndpoints */ @@ -560,7 +556,20 @@ public final class TcpServerEndpoint imp String localHost = host; if (localHost == null) { - if (exception != null) throw exception; + /* + * Only expose UnknownHostException thrown directly by + * InetAddress.getLocalHost if it would also be thrown + * in the caller's security context; otherwise, throw + * a new UnknownHostException without the host name. + */ + if (exception != null){ + try { + exposeLocalAdd.checkGuard(null); + } catch (SecurityException e){ + throw new UnknownHostException("access to resolve local host denied"); + } + throw exception; + } SecurityManager sm = System.getSecurityManager(); if (sm != null) { try {
