diff options
author | Gary Benson <gbenson@redhat.com> | 2006-09-01 15:38:00 +0000 |
---|---|---|
committer | Gary Benson <gary@gcc.gnu.org> | 2006-09-01 15:38:00 +0000 |
commit | 69afd3217ed5b3a232363a518bb1e2174e8797fc (patch) | |
tree | afb0ee26e7027ffac4137c59097ef2f0982a6049 | |
parent | 429b876b0784f5f4406eadf56115a8b4c20e874d (diff) | |
download | gcc-69afd3217ed5b3a232363a518bb1e2174e8797fc.zip gcc-69afd3217ed5b3a232363a518bb1e2174e8797fc.tar.gz gcc-69afd3217ed5b3a232363a518bb1e2174e8797fc.tar.bz2 |
InetAddress.java (getLocalHost): Refactor to avoid security check if getLocalHostname() fails and to provide...
2006-09-01 Gary Benson <gbenson@redhat.com>
* java/net/InetAddress.java (getLocalHost): Refactor to avoid
security check if getLocalHostname() fails and to provide more
meaningful exceptions it the security check fails.
From-SVN: r116627
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/java/net/InetAddress.java | 36 |
2 files changed, 18 insertions, 24 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 65dcba1..594e2f2 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,11 @@ 2006-09-01 Gary Benson <gbenson@redhat.com> + * java/net/InetAddress.java (getLocalHost): Refactor to avoid + security check if getLocalHostname() fails and to provide more + meaningful exceptions it the security check fails. + +2006-09-01 Gary Benson <gbenson@redhat.com> + * java/net/InetAddress.java (getByAddress): Create Inet4Address objects when passed IPv4-mapped IPv6 addresses. (getByName, getAllByName): Defer to the above to ensure that the diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java index 5bb9c0f..995e897 100644 --- a/libjava/java/net/InetAddress.java +++ b/libjava/java/net/InetAddress.java @@ -706,7 +706,10 @@ public class InetAddress implements Serializable String hostname = getLocalHostname(); - if (s != null) + if (hostname == null || hostname.length() == 0) + throw new UnknownHostException(); + + try { // "The Java Class Libraries" suggests that if the security // manager disallows getting the local host name, then @@ -714,37 +717,22 @@ public class InetAddress implements Serializable // However, the JDK 1.2 API claims to throw SecurityException, // which seems to suggest SecurityException is *not* caught. // In this case, experimentation shows that former is correct. - try + if (s != null) { // This is wrong, if the name returned from getLocalHostname() // is not a fully qualified name. FIXME. s.checkConnect (hostname, -1); } - catch (SecurityException ex) - { - hostname = null; - } + + localhost = new InetAddress (null, null); + lookup (hostname, localhost, false); } - - if (hostname != null && hostname.length() != 0) + catch (Exception ex) { - try - { - localhost = new InetAddress (null, null); - lookup (hostname, localhost, false); - } - catch (Exception ex) - { - UnknownHostException failure = new UnknownHostException(hostname); - failure.initCause(ex); - throw failure; - } + UnknownHostException failure = new UnknownHostException(hostname); + failure.initCause(ex); + throw failure; } - else - throw new UnknownHostException(); - - if (localhost == null) - localhost = new InetAddress (loopbackAddress, "localhost"); } /** |