Skip to content

Commit

Permalink
config: show missing section error correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Mar 13, 2020
1 parent 4d77bd8 commit f5d2fd6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tunnel/src/main/java/com/wireguard/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static Config parse(final BufferedReader reader)
final Collection<String> 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('#');
Expand All @@ -86,6 +87,7 @@ public static Config parse(final BufferedReader reader)
if ("[Interface]".equalsIgnoreCase(line)) {
inInterfaceSection = true;
inPeerSection = false;
seenInterfaceSection = true;
} else if ("[Peer]".equalsIgnoreCase(line)) {
inInterfaceSection = false;
inPeerSection = true;
Expand All @@ -104,7 +106,7 @@ public static Config parse(final BufferedReader reader)
}
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.
Expand Down

0 comments on commit f5d2fd6

Please sign in to comment.