From 7dc50989da53bbc6b2fdc3d66ac4715fad2b5f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 19 Apr 2026 15:01:42 +0200 Subject: [PATCH] Revisited localhost and loopback resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../com/sun/corba/ee/impl/orb/ORBImpl.java | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/orbmain/src/main/java/com/sun/corba/ee/impl/orb/ORBImpl.java b/orbmain/src/main/java/com/sun/corba/ee/impl/orb/ORBImpl.java index 270c0177b4..7dfe98c4be 100644 --- a/orbmain/src/main/java/com/sun/corba/ee/impl/orb/ORBImpl.java +++ b/orbmain/src/main/java/com/sun/corba/ee/impl/orb/ORBImpl.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2026 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2020 Oracle and/or its affiliates. * * This program and the accompanying materials are made available under the @@ -91,9 +92,11 @@ import java.applet.Applet; import java.io.IOException ; +import java.lang.System.Logger; import java.lang.reflect.Constructor; import java.net.InetAddress ; import java.util.ArrayList ; +import java.net.UnknownHostException; import java.util.Arrays; import java.util.HashMap ; import java.util.HashSet ; @@ -107,8 +110,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock ; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.rmi.CORBA.ValueHandler; @@ -133,14 +134,16 @@ import org.omg.CORBA.portable.ValueFactory; import static com.sun.corba.ee.spi.misc.ORBConstants.SKIP_GMBAL_INIT; +import static java.lang.System.Logger.Level.TRACE; +import static java.lang.System.Logger.Level.WARNING; /** * The JavaIDL ORB implementation. */ @OrbLifeCycle @Subcontract -public class ORBImpl extends com.sun.corba.ee.spi.orb.ORB -{ +public class ORBImpl extends com.sun.corba.ee.spi.orb.ORB { + private static final Logger LOG = System.getLogger(ORBImpl.class.getName()); private boolean set_parameters_called = false ; protected TransportManager transportManager; @@ -468,13 +471,12 @@ public ConfigParser( boolean disableORBD ) { if (!disableORBD) { // Note: this class is NOT included in the GF bundles! // Try to load it if present. - String cname = - "com.sun.corba.ee.impl.activation.ORBConfiguratorPersistentImpl" ; + String cname = "com.sun.corba.ee.impl.activation.ORBConfiguratorPersistentImpl"; try { configurator = Class.forName(cname); - } catch (ClassNotFoundException ex) { - Logger.getLogger(ORBImpl.class.getName()).log(Level.FINE, null, ex); + } catch (ClassNotFoundException e) { + LOG.log(TRACE, "Failed to load alternative configurator class " + cname, e); } } } @@ -1707,20 +1709,26 @@ public ServiceContextsCache getServiceContextsCache() return serviceContextsCache; } - // XXX All of the isLocalYYY checking needs to be revisited. - // First of all, all three of these methods are called from - // only one place in impl.ior.IORImpl. Second, we have problems - // both with multi-homed hosts and with multi-profile IORs. - // A possible strategy: like the LocalClientRequestDispatcher, we need - // to determine this more abstractly at the ContactInfo level. - // This level should probably just get the CorbaContactInfoList from - // the IOR, then iterator over ContactInfo. If any ContactInfo is - // local, the IOR is local, and we can pick one to create the - // LocalClientRequestDispatcher as well. Bottom line: this code needs to move. - public boolean isLocalHost( String hostName ) - { - return hostName.equals( configData.getORBServerHost() ) || - hostName.equals( getLocalHostName() ) ; + @Override + public boolean isLocalHost(String hostName) { + try { + return hostName.equals(configData.getORBServerHost()) + || hostName.equals(getLocalHostName()) + || isLocalHost(InetAddress.getByName(hostName)); + } catch (UnknownHostException e) { + return false; + } + } + + private boolean isLocalHost(InetAddress address) { + if (address.isLoopbackAddress()) { + return true; + } + String ip = address.getHostAddress(); + if (ip == null) { + return false; + } + return ip.equals(configData.getORBServerHost()) || ip.equals(getLocalHostName()); } @Subcontract @@ -1753,41 +1761,32 @@ public boolean isLocalServerId( int subcontractId, int serverId ) } } - /************************************************************************* - * The following public methods are for ORB shutdown. - *************************************************************************/ - - private String getHostName(String host) - throws java.net.UnknownHostException - { - return InetAddress.getByName( host ).getHostAddress(); - } - - /* keeping a copy of the getLocalHostName so that it can only be called + /* keeping a copy of the getLocalHostName so that it can only be called * internally and the unauthorized clients cannot have access to the - * localHost information, originally, the above code was calling - * getLocalHostName from Connection.java. If the hostname is cached in + * localHost information, originally, the above code was calling + * getLocalHostName from Connection.java. If the hostname is cached in * Connection.java, then * it is a security hole, since any unauthorized client has access to * the host information. With this change it is used internally so the - * security problem is resolved. Also in Connection.java, the - * getLocalHost() implementation has changed to always call the + * security problem is resolved. Also in Connection.java, the + * getLocalHost() implementation has changed to always call the * InetAddress.getLocalHost().getHostAddress() * The above mentioned method has been removed from the connection class */ - private static String localHostString = null; + private static String localHostString; - private synchronized String getLocalHostName() - { + private synchronized String getLocalHostName() { if (localHostString == null) { try { - localHostString = InetAddress.getLocalHost().getHostAddress(); - } catch (Exception ex) { - throw wrapper.getLocalHostFailed( ex ) ; + localHostString = InetAddress.getLocalHost().getHostName(); + } catch (Exception e) { + LOG.log(WARNING, "Failed to resolve local hostname, falling back to loopback. " + + "isLocalHost() checks may be unreliable.", e); + localHostString = InetAddress.getLoopbackAddress().getHostName(); } } - return localHostString ; + return localHostString; } /******************************************************************************