From f5d2fd61904e0b1e1828331009d5be62851d7371 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 13 Mar 2020 13:20:21 -0600 Subject: config: show missing section error correctly Signed-off-by: Jason A. Donenfeld --- tunnel/src/main/java/com/wireguard/config/Config.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tunnel/src/main/java/com/wireguard') diff --git a/tunnel/src/main/java/com/wireguard/config/Config.java b/tunnel/src/main/java/com/wireguard/config/Config.java index c45dccb6..df344b1c 100644 --- a/tunnel/src/main/java/com/wireguard/config/Config.java +++ b/tunnel/src/main/java/com/wireguard/config/Config.java @@ -69,6 +69,7 @@ public final class Config { final Collection peerLines = new ArrayList<>(); boolean inInterfaceSection = false; boolean inPeerSection = false; + boolean seenInterfaceSection = false; @Nullable String line; while ((line = reader.readLine()) != null) { final int commentIndex = line.indexOf('#'); @@ -86,6 +87,7 @@ public final class Config { if ("[Interface]".equalsIgnoreCase(line)) { inInterfaceSection = true; inPeerSection = false; + seenInterfaceSection = true; } else if ("[Peer]".equalsIgnoreCase(line)) { inInterfaceSection = false; inPeerSection = true; @@ -104,7 +106,7 @@ public final class Config { } if (inPeerSection) builder.parsePeer(peerLines); - else if (!inInterfaceSection) + if (!seenInterfaceSection) throw new BadConfigException(Section.CONFIG, Location.TOP_LEVEL, Reason.MISSING_SECTION, null); // Combine all [Interface] sections in the file. -- cgit v1.2.3