[automerge] Stop using invalid URL to prevent unexpected crash 2p: fe57c5bf89

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18714947

Bug: 219498290
Change-Id: I31f338fe54722f0291f90c5f6eb37fef4d31b77f
Merged-In: I22903414380b62051f514e43b93af992f45740b4
This commit is contained in:
Chiachang Wang
2022-06-02 09:54:44 +00:00
committed by Presubmit Automerger Backend

View File

@@ -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"));