Merge "Stop using invalid URL to prevent unexpected crash" into qt-dev am: 3ac8d1dc2f am: dadbab8ae8

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

Change-Id: I24a2ceeab11b6b9b9582bb846524ef46eaf8d6ba
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chiachang Wang
2022-06-08 02:15:59 +00:00
committed by Automerger Merge Worker

View File

@@ -37,6 +37,7 @@ import android.os.SystemClock;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.webkit.URLUtil;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.TrafficStatsConstants; import com.android.internal.util.TrafficStatsConstants;
@@ -215,8 +216,22 @@ public class PacManager {
* @throws IOException if the URL is malformed, or the PAC file is too big. * @throws IOException if the URL is malformed, or the PAC file is too big.
*/ */
private static String get(Uri pacUri) throws IOException { private static String get(Uri pacUri) throws IOException {
URL url = new URL(pacUri.toString()); if (!URLUtil.isValidUrl(pacUri.toString())) {
URLConnection urlConnection = url.openConnection(java.net.Proxy.NO_PROXY); 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; long contentLength = -1;
try { try {
contentLength = Long.parseLong(urlConnection.getHeaderField("Content-Length")); contentLength = Long.parseLong(urlConnection.getHeaderField("Content-Length"));