From 97eba6ba41c86125a740f909b8ab9fd52407a691 Mon Sep 17 00:00:00 2001 From: Raj Mamadgi Date: Mon, 11 Nov 2013 13:52:58 -0800 Subject: [PATCH] Fix for the invalid Global Proxy Setting b/11598568 Adding validation for Global Proxy setting before it is being set. Proxy is validated at the boot time also to make sure the value set is valid. Change-Id: Ib93d24a80af1a329694f07c47bd81dfcc1e1b874 Signed-off-by: Raj Mamadgi --- core/java/android/net/ProxyProperties.java | 10 ++++++++++ .../com/android/server/ConnectivityService.java | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java index 9c4772b90f..a4157c9225 100644 --- a/core/java/android/net/ProxyProperties.java +++ b/core/java/android/net/ProxyProperties.java @@ -115,6 +115,16 @@ public class ProxyProperties implements Parcelable { return false; } + public boolean isValid() { + try { + Proxy.validate(mHost == null ? "" : mHost, mPort == 0 ? "" : Integer.toString(mPort), + mExclusionList == null ? "" : mExclusionList); + } catch (IllegalArgumentException e) { + return false; + } + return true; + } + public java.net.Proxy makeProxy() { java.net.Proxy proxy = java.net.Proxy.NO_PROXY; if (mHost != null) { diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 29c546e197..b2fb2bb515 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -3114,6 +3114,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { int port = 0; String exclList = ""; if (proxyProperties != null && !TextUtils.isEmpty(proxyProperties.getHost())) { + if (!proxyProperties.isValid()) { + if (DBG) + log("Invalid proxy properties, ignoring: " + proxyProperties.toString()); + return; + } mGlobalProxy = new ProxyProperties(proxyProperties); host = mGlobalProxy.getHost(); port = mGlobalProxy.getPort(); @@ -3147,6 +3152,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST); if (!TextUtils.isEmpty(host)) { ProxyProperties proxyProperties = new ProxyProperties(host, port, exclList); + if (!proxyProperties.isValid()) { + if (DBG) log("Invalid proxy properties, ignoring: " + proxyProperties.toString()); + return; + } + synchronized (mProxyLock) { mGlobalProxy = proxyProperties; } @@ -3170,6 +3180,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { synchronized (mProxyLock) { if (mDefaultProxy != null && mDefaultProxy.equals(proxy)) return; if (mDefaultProxy == proxy) return; // catches repeated nulls + if (!proxy.isValid()) { + if (DBG) log("Invalid proxy properties, ignoring: " + proxy.toString()); + return; + } mDefaultProxy = proxy; if (mGlobalProxy != null) return;