diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 8835fbdd..4b7ae518 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -630,7 +630,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else if ("vpn4".equals(name)) { String vpn4 = prefs.getString(name, null); try { - checkAddress(vpn4); + checkAddress(vpn4, false); prefs.edit().putString(name, vpn4.trim()).apply(); } catch (Throwable ex) { prefs.edit().remove(name).apply(); @@ -645,7 +645,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere } else if ("vpn6".equals(name)) { String vpn6 = prefs.getString(name, null); try { - checkAddress(vpn6); + checkAddress(vpn6, false); prefs.edit().putString(name, vpn6.trim()).apply(); } catch (Throwable ex) { prefs.edit().remove(name).apply(); @@ -660,7 +660,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere } else if ("dns".equals(name) || "dns2".equals(name)) { String dns = prefs.getString(name, null); try { - checkAddress(dns); + checkAddress(dns, true); prefs.edit().putString(name, dns.trim()).apply(); } catch (Throwable ex) { prefs.edit().remove(name).apply(); @@ -783,16 +783,18 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere ServiceSinkhole.reload("permission granted", this, false); } - private void checkAddress(String address) throws IllegalArgumentException, UnknownHostException { + private void checkAddress(String address, boolean allow_local) throws IllegalArgumentException, UnknownHostException { if (address != null) address = address.trim(); if (TextUtils.isEmpty(address)) throw new IllegalArgumentException("Bad address"); if (!Util.isNumericAddress(address)) throw new IllegalArgumentException("Bad address"); - InetAddress idns = InetAddress.getByName(address); - if (idns.isLoopbackAddress() || idns.isAnyLocalAddress()) - throw new IllegalArgumentException("Bad address"); + if (!allow_local) { + InetAddress iaddr = InetAddress.getByName(address); + if (iaddr.isLoopbackAddress() || iaddr.isAnyLocalAddress()) + throw new IllegalArgumentException("Bad address"); + } } private BroadcastReceiver interactiveStateReceiver = new BroadcastReceiver() {