Merge branch 'invalid-port' into 'master'

Quick fix for people entering a huge port number for proxy settings

Closes acra-crash-reports#179

See merge request fdroid/fdroidclient!1187
This commit is contained in:
Hans-Christoph Steiner 2023-02-01 14:46:13 +00:00
commit efe1e0680f
1 changed files with 6 additions and 6 deletions

View File

@ -31,6 +31,10 @@ import android.os.Build;
import android.text.format.DateUtils;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.installer.PrivilegedInstaller;
import org.fdroid.fdroid.net.ConnectivityMonitorService;
@ -44,10 +48,6 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
/**
* Handles shared preferences for FDroid, looking after the names of
* preferences, default values and caching. Needs to be setup in the FDroidApp
@ -506,11 +506,11 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public int getProxyPort() {
final String port = preferences.getString(PREF_PROXY_PORT, String.valueOf(DEFAULT_PROXY_PORT));
try {
return Integer.parseInt(port);
return Math.min(Integer.parseInt(port), 65535);
} catch (NumberFormatException e) {
// hack until this can be a number-only preference
try {
return Integer.parseInt(port.replaceAll("[^0-9]", ""));
return Math.min(Integer.parseInt(port.replaceAll("[^0-9]", "")), 65535);
} catch (Exception e1) {
return DEFAULT_PROXY_PORT;
}