Hi again,

This commit makes InetAddress.getCanonicalHostName() perform its
security check on the canonical hostname (ie after the lookup).
It also makes getHostname() call getCanonicalHostName() rather than
the other way around, so getHostname() picks up the security check,
and getCanonicalHostName() doesn't have to create throwaway objects.

Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.8515
diff -u -r1.8515 ChangeLog
--- ChangeLog   8 Sep 2006 11:32:34 -0000       1.8515
+++ ChangeLog   8 Sep 2006 12:54:58 -0000
@@ -1,3 +1,10 @@
+2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
+
+       * java/net/InetAddress.java
+       (getHostName): Move lookup into getCanonicalHostName.
+       (getCanonicalHostName): Move lookup from getHostName,
+       Perform security check on canonical name (ie after lookup).
+
 2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
 
        * java/net/Inet4Address.java (isMulticastAddress,
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/InetAddress.java,v
retrieving revision 1.48
diff -u -r1.48 InetAddress.java
--- java/net/InetAddress.java   8 Sep 2006 11:32:34 -0000       1.48
+++ java/net/InetAddress.java   8 Sep 2006 12:54:58 -0000
@@ -307,17 +307,8 @@
    */
   public String getHostName()
   {
-    if (hostName != null)
-      return hostName;
-
-    try
-      {
-       hostName = VMInetAddress.getHostByAddr(addr);
-      }
-    catch (UnknownHostException e)
-      {
-       hostName = getHostAddress();
-      }
+    if (hostName == null)
+      hostName = getCanonicalHostName();
 
     return hostName;
   }
@@ -329,12 +320,22 @@
    */
   public String getCanonicalHostName()
   {
+    String hostname;
+    try
+      {
+       hostname = VMInetAddress.getHostByAddr(addr);
+      }
+    catch (UnknownHostException e)
+      {
+       return getHostAddress();
+      }
+
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       {
         try
          {
-            sm.checkConnect(hostName, -1);
+            sm.checkConnect(hostname, -1);
          }
        catch (SecurityException e)
          {
@@ -342,16 +343,7 @@
          }
       }
 
-    // Try to find the FDQN now
-    InetAddress address;
-    byte[] ipaddr = getAddress();
-
-    if (ipaddr.length == 16)
-      address = new Inet6Address(getAddress(), null);
-    else
-      address = new Inet4Address(getAddress(), null);
-
-    return address.getHostName();
+    return hostname;
   }
 
   /**

Reply via email to