From 6b7af6055f25022361beb2c169d2c1835922dc32 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 4 Nov 2010 16:46:00 -0700 Subject: Use InetAddress.isNumeric. This code is trying to detect anything equivalent to localhost, but without accidentally causing a DNS lookup. Bug: 3073384 Change-Id: Ib611c8ca46059e00b07fc4b94d4af777217da1fb --- core/java/android/net/Proxy.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java index 23a3ea85d168..21c485e70e18 100644 --- a/core/java/android/net/Proxy.java +++ b/core/java/android/net/Proxy.java @@ -299,15 +299,18 @@ public final class Proxy { final URI uri = URI.create(url); final String host = uri.getHost(); if (host != null) { - // TODO: InetAddress.isLoopbackAddress should be used to check - // for localhost. However no public factory methods exist which - // can be used without triggering DNS lookup if host is not localhost. - if (host.equalsIgnoreCase("localhost") || - host.equals("127.0.0.1") || - host.equals("[::1]")) { + if (host.equalsIgnoreCase("localhost")) { return true; } + // Check we have a numeric address so we don't cause a DNS lookup in getByName. + if (InetAddress.isNumeric(host)) { + if (InetAddress.getByName(host).isLoopbackAddress()) { + return true; + } + } } + } catch (UnknownHostException ignored) { + // Can't happen for a numeric address (InetAddress.getByName). } catch (IllegalArgumentException iex) { // Ignore (URI.create) } -- cgit v1.2.3-59-g8ed1b