aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/config/Peer.java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-24 03:31:10 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-27 05:43:07 +0200
commit9ee976823dfc18e7ba5cf885b92032504b060ed9 (patch)
treef37eff642be7f8aca29fd14df07377b2488d283b /app/src/main/java/com/wireguard/config/Peer.java
parentLatest go changes (diff)
downloadwireguard-android-9ee976823dfc18e7ba5cf885b92032504b060ed9.tar.xz
wireguard-android-9ee976823dfc18e7ba5cf885b92032504b060ed9.zip
Throw IllegalArgumentExceptions when arguments are bad
This will make the two way data binding crash more, but it will improve the robustness of the config file parser, which deals with exceptions gracefully, and when we move to one way data binding, it will help with that too. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Peer.java')
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java27
1 files changed, 12 insertions, 15 deletions
diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java
index 58f2633f..c2b23e9f 100644
--- a/app/src/main/java/com/wireguard/config/Peer.java
+++ b/app/src/main/java/com/wireguard/config/Peer.java
@@ -125,7 +125,7 @@ public class Peer extends BaseObservable implements Parcelable {
return publicKey;
}
- public void parse(final String line) throws UnknownHostException {
+ public void parse(final String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ALLOWED_IPS)
addAllowedIPs(key.parseList(line));
@@ -141,11 +141,11 @@ public class Peer extends BaseObservable implements Parcelable {
throw new IllegalArgumentException(line);
}
- public void addAllowedIPs(String[] allowedIPs) throws UnknownHostException {
+ public void addAllowedIPs(String[] allowedIPs) {
if (allowedIPs != null && allowedIPs.length > 0) {
for (final String allowedIP : allowedIPs) {
if (allowedIP.isEmpty())
- throw new UnknownHostException("{empty}");
+ throw new IllegalArgumentException("AllowedIP is empty");
this.allowedIPsList.add(new IPCidr(allowedIP));
}
}
@@ -154,12 +154,8 @@ public class Peer extends BaseObservable implements Parcelable {
}
public void setAllowedIPsString(final String allowedIPsString) {
- try {
- this.allowedIPsList.clear();
- addAllowedIPs(Attribute.stringToList(allowedIPsString));
- } catch (Exception e) {
- this.allowedIPsList.clear();
- }
+ this.allowedIPsList.clear();
+ addAllowedIPs(Attribute.stringToList(allowedIPsString));
}
public void setEndpoint(InetSocketAddress endpoint) {
@@ -171,14 +167,15 @@ public class Peer extends BaseObservable implements Parcelable {
public void setEndpointString(final String endpoint) {
if (endpoint != null && !endpoint.isEmpty()) {
InetSocketAddress constructedEndpoint;
+ if (endpoint.indexOf('/') != -1 || endpoint.indexOf('?') != -1 || endpoint.indexOf('#') != -1)
+ throw new IllegalArgumentException("Forbidden characters in endpoint");
+ URI uri;
try {
- if (endpoint.indexOf('/') != -1 || endpoint.indexOf('?') != -1 || endpoint.indexOf('#') != -1)
- throw new Exception();
- URI uri = new URI("wg://" + endpoint);
- constructedEndpoint = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
- } catch (Exception e) {
- return; /* XXX: Uh oh. */
+ uri = new URI("wg://" + endpoint);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
}
+ constructedEndpoint = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
setEndpoint(constructedEndpoint);
} else
setEndpoint(null);