summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRobert Greenwalt <rgreenwalt@google.com>2011-02-22 16:00:42 -0800
committerRobert Greenwalt <rgreenwalt@google.com>2011-03-02 11:37:32 -0800
commite590373ea71251cfffc8f22f011e2e6335dce716 (patch)
tree4fb1c57267a51143b6a0ebaf10174ae89280b6c2 /core
parent0390191392e62314d9dfeba655f737a0e2594950 (diff)
downloadframeworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.zip
frameworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.tar.gz
frameworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.tar.bz2
Start using NetworkUtils.numericToInetAddress.
Generates InetAddresses without risking an accidental dns lookup. For use with supposedly numeric-only ip address strings. Change-Id: I694f3976ce1c6382854706f6557ea88a289add3a
Diffstat (limited to 'core')
-rw-r--r--core/java/android/net/Proxy.java10
-rw-r--r--core/java/android/server/BluetoothPanProfileHandler.java7
-rw-r--r--core/java/com/android/internal/net/DomainNameValidator.java26
3 files changed, 11 insertions, 32 deletions
diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java
index f750122..a408ea0 100644
--- a/core/java/android/net/Proxy.java
+++ b/core/java/android/net/Proxy.java
@@ -233,17 +233,11 @@ public final class Proxy {
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;
- }
+ if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
+ return true;
}
}
- } catch (UnknownHostException ignored) {
- // Can't happen for a numeric address (InetAddress.getByName).
} catch (IllegalArgumentException iex) {
- // Ignore (URI.create)
}
return false;
}
diff --git a/core/java/android/server/BluetoothPanProfileHandler.java b/core/java/android/server/BluetoothPanProfileHandler.java
index fb96439..5476d7b 100644
--- a/core/java/android/server/BluetoothPanProfileHandler.java
+++ b/core/java/android/server/BluetoothPanProfileHandler.java
@@ -28,6 +28,7 @@ import android.content.res.Resources.NotFoundException;
import android.net.ConnectivityManager;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
+import android.net.NetworkUtils;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.ServiceManager;
@@ -365,9 +366,9 @@ final class BluetoothPanProfileHandler {
if (ifcg != null) {
InetAddress addr = null;
if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null ||
- addr.equals(InetAddress.getByName("0.0.0.0")) ||
- addr.equals(InetAddress.getByName("::0"))) {
- addr = InetAddress.getByName(address);
+ addr.equals(NetworkUtils.numericToInetAddress("0.0.0.0")) ||
+ addr.equals(NetworkUtils.numericToInetAddress("::0"))) {
+ addr = NetworkUtils.numericToInetAddress(address);
}
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
diff --git a/core/java/com/android/internal/net/DomainNameValidator.java b/core/java/com/android/internal/net/DomainNameValidator.java
index dbd5019..36973f1 100644
--- a/core/java/com/android/internal/net/DomainNameValidator.java
+++ b/core/java/com/android/internal/net/DomainNameValidator.java
@@ -15,12 +15,11 @@
*/
package com.android.internal.net;
-
+import android.net.NetworkUtils;
import android.util.Config;
import android.util.Log;
import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.Collection;
@@ -38,13 +37,6 @@ public class DomainNameValidator {
private static final boolean DEBUG = false;
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
- private static Pattern QUICK_IP_PATTERN;
- static {
- try {
- QUICK_IP_PATTERN = Pattern.compile("^[a-f0-9\\.:]+$");
- } catch (PatternSyntaxException e) {}
- }
-
private static final int ALT_DNS_NAME = 2;
private static final int ALT_IPA_NAME = 7;
@@ -75,19 +67,11 @@ public class DomainNameValidator {
if (rval) {
try {
// do a quick-dirty IP match first to avoid DNS lookup
- rval = QUICK_IP_PATTERN.matcher(domain).matches();
- if (rval) {
- rval = domain.equals(
- InetAddress.getByName(domain).getHostAddress());
- }
- } catch (UnknownHostException e) {
- String errorMessage = e.getMessage();
- if (errorMessage == null) {
- errorMessage = "unknown host exception";
- }
-
+ rval = domain.equals(
+ NetworkUtils.numericToInetAddress(domain).getHostAddress());
+ } catch (IllegalArgumentException e) {
if (LOG_ENABLED) {
- Log.v(TAG, "DomainNameValidator.isIpAddress(): " + errorMessage);
+ Log.v(TAG, "DomainNameValidator.isIpAddress(): " + e);
}
rval = false;