aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/config/Config.java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-26 23:45:41 +0100
committerSamuel Holland <samuel@sholland.org>2017-11-26 23:45:41 +0100
commite421b997cd31088ca9cec96199b7acf965483eaa (patch)
treecbf3bd8a5893553a9a9841a105a0e19adc05d7c0 /app/src/main/java/com/wireguard/config/Config.java
parentConfigImporter: Get filename from content resolver (diff)
downloadwireguard-android-e421b997cd31088ca9cec96199b7acf965483eaa.tar.xz
wireguard-android-e421b997cd31088ca9cec96199b7acf965483eaa.zip
Config: make parsing stricter
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Config.java')
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java
index 2a282d09..d5f0c6e5 100644
--- a/app/src/main/java/com/wireguard/config/Config.java
+++ b/app/src/main/java/com/wireguard/config/Config.java
@@ -139,19 +139,27 @@ public class Config extends BaseObservable
new InputStreamReader(stream, StandardCharsets.UTF_8))) {
Peer currentPeer = null;
String line;
+ boolean inInterfaceSection = false;
while ((line = reader.readLine()) != null) {
- if (line.isEmpty())
+ if (line.isEmpty() || line.startsWith("#"))
continue;
if ("[Interface]".equals(line)) {
currentPeer = null;
+ inInterfaceSection = true;
} else if ("[Peer]".equals(line)) {
currentPeer = addPeer();
- } else if (currentPeer == null) {
+ inInterfaceSection = false;
+ } else if (inInterfaceSection) {
iface.parse(line);
- } else {
+ } else if (currentPeer != null) {
currentPeer.parse(line);
+ } else {
+ throw new IllegalArgumentException("Invalid configuration line: " + line);
}
}
+ if (!inInterfaceSection && currentPeer == null) {
+ throw new IllegalArgumentException("Did not find any config information");
+ }
}
}