summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chiachang Wang <chiachangwang@google.com> 2022-06-08 01:30:27 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-06-08 01:30:27 +0000
commitbc599a04dc8ecee78a5502a2c696a91fd639f67a (patch)
tree6d0dcb5bb48a6c2d7450419e8a4e48b2c40e0bb8
parent20e1cbc19525486b2ddce5313d4a06faf9a875ff (diff)
parent3b807215722438743cf24dcbcf661a8e53d6f2e9 (diff)
Merge changes from topic "cherrypicker-L08900000954891083:N79200001270491487" into sc-qpr1-dev
* changes: [automerge] Stop using invalid URL to prevent unexpected crash 2p: fe57c5bf89 Stop using invalid URL to prevent unexpected crash
-rw-r--r--services/core/java/com/android/server/connectivity/PacProxyService.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/connectivity/PacProxyService.java b/services/core/java/com/android/server/connectivity/PacProxyService.java
index 00703390a118..38b386f683c2 100644
--- a/services/core/java/com/android/server/connectivity/PacProxyService.java
+++ b/services/core/java/com/android/server/connectivity/PacProxyService.java
@@ -44,6 +44,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;
+import android.webkit.URLUtil;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.TrafficStatsConstants;
@@ -232,8 +233,22 @@ public class PacProxyService extends IPacProxyManager.Stub {
* @throws IOException if the URL is malformed, or the PAC file is too big.
*/
private static String get(Uri pacUri) throws IOException {
- URL url = new URL(pacUri.toString());
- URLConnection urlConnection = url.openConnection(java.net.Proxy.NO_PROXY);
+ if (!URLUtil.isValidUrl(pacUri.toString())) {
+ throw new IOException("Malformed URL:" + pacUri);
+ }
+
+ final URL url = new URL(pacUri.toString());
+ URLConnection urlConnection;
+ try {
+ urlConnection = url.openConnection(java.net.Proxy.NO_PROXY);
+ // Catch the possible exceptions and rethrow as IOException to not to crash the system
+ // for illegal input.
+ } catch (IllegalArgumentException e) {
+ throw new IOException("Incorrect proxy type for " + pacUri);
+ } catch (UnsupportedOperationException e) {
+ throw new IOException("Unsupported URL connection type for " + pacUri);
+ }
+
long contentLength = -1;
try {
contentLength = Long.parseLong(urlConnection.getHeaderField("Content-Length"));