From 117a94177aab6277c45ce41767c4412cb77ecdf9 Mon Sep 17 00:00:00 2001
From: gary <gary@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 1 Sep 2006 10:06:13 +0000
Subject: [PATCH] 2006-09-01  Gary Benson  <gbenson@redhat.com>

	* java/net/InetAddress.java (getByName, getAllByName):
	Only perform security check when DNS lookups are required.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116621 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libjava/ChangeLog                 |  5 +++++
 libjava/java/net/InetAddress.java | 22 ++++++++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 91a90b6a37fe..833ae3f2f953 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-01  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/InetAddress.java (getByName, getAllByName):
+	Only perform security check when DNS lookups are required.
+
 2006-08-31  Keith Seitz  <keiths@redhat.com>
 
 	* include/jvmti_md.h: New file.
diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java
index 6ca72fe3e244..1c312940c83f 100644
--- a/libjava/java/net/InetAddress.java
+++ b/libjava/java/net/InetAddress.java
@@ -592,14 +592,10 @@ public class InetAddress implements Serializable
     throws UnknownHostException
   {
     // If null or the empty string is supplied, the loopback address
-    // is returned. Note that this is permitted without a security check.
+    // is returned.
     if (hostname == null || hostname.length() == 0)
       return loopback;
 
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkConnect(hostname, -1);
-
     // Assume that the host string is an IP address
     byte[] address = aton(hostname);
     if (address != null)
@@ -623,6 +619,11 @@ public class InetAddress implements Serializable
           throw new UnknownHostException ("Address has invalid length");
       }
 
+    // Perform security check before resolving
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkConnect(hostname, -1);
+
     // Try to resolve the host by DNS
     InetAddress result = new InetAddress(null, null);
     lookup (hostname, result, false);
@@ -650,14 +651,10 @@ public class InetAddress implements Serializable
     throws UnknownHostException
   {
     // If null or the empty string is supplied, the loopback address
-    // is returned. Note that this is permitted without a security check.
+    // is returned.
     if (hostname == null || hostname.length() == 0)
       return new InetAddress[] {loopback};
 
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkConnect(hostname, -1);
-
     // Check if hostname is an IP address
     byte[] address = aton (hostname);
     if (address != null)
@@ -667,6 +664,11 @@ public class InetAddress implements Serializable
 	return result;
       }
 
+    // Perform security check before resolving
+    SecurityManager s = System.getSecurityManager();
+    if (s != null)
+      s.checkConnect(hostname, -1);
+
     // Try to resolve the hostname by DNS
     return lookup (hostname, null, true);
   }
-- 
GitLab