mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-01-18 22:39:08 +00:00
Config file parsing: Fix bug when there are comments at the end
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
2fe9f83ba5
commit
812e660491
@ -54,38 +54,38 @@ extension TunnelConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trimmedLine = trimmedLine.trimmingCharacters(in: .whitespaces)
|
trimmedLine = trimmedLine.trimmingCharacters(in: .whitespaces)
|
||||||
|
let lowercasedLine = trimmedLine.lowercased()
|
||||||
|
|
||||||
guard !trimmedLine.isEmpty else { continue }
|
if !trimmedLine.isEmpty {
|
||||||
let lowercasedLine = line.lowercased()
|
if let equalsIndex = line.firstIndex(of: "=") {
|
||||||
|
// Line contains an attribute
|
||||||
if let equalsIndex = line.firstIndex(of: "=") {
|
let keyWithCase = line[..<equalsIndex].trimmingCharacters(in: .whitespaces)
|
||||||
// Line contains an attribute
|
let key = keyWithCase.lowercased()
|
||||||
let keyWithCase = line[..<equalsIndex].trimmingCharacters(in: .whitespaces)
|
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
|
||||||
let key = keyWithCase.lowercased()
|
let keysWithMultipleEntriesAllowed: Set<String> = ["address", "allowedips", "dns"]
|
||||||
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
|
if let presentValue = attributes[key] {
|
||||||
let keysWithMultipleEntriesAllowed: Set<String> = ["address", "allowedips", "dns"]
|
if keysWithMultipleEntriesAllowed.contains(key) {
|
||||||
if let presentValue = attributes[key] {
|
attributes[key] = presentValue + "," + value
|
||||||
if keysWithMultipleEntriesAllowed.contains(key) {
|
} else {
|
||||||
attributes[key] = presentValue + "," + value
|
throw ParseError.multipleEntriesForKey(keyWithCase)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw ParseError.multipleEntriesForKey(keyWithCase)
|
attributes[key] = value
|
||||||
}
|
}
|
||||||
} else {
|
let interfaceSectionKeys: Set<String> = ["privatekey", "listenport", "address", "dns", "mtu"]
|
||||||
attributes[key] = value
|
let peerSectionKeys: Set<String> = ["publickey", "presharedkey", "allowedips", "endpoint", "persistentkeepalive"]
|
||||||
|
if parserState == .inInterfaceSection {
|
||||||
|
guard interfaceSectionKeys.contains(key) else {
|
||||||
|
throw ParseError.interfaceHasUnrecognizedKey(keyWithCase)
|
||||||
|
}
|
||||||
|
} else if parserState == .inPeerSection {
|
||||||
|
guard peerSectionKeys.contains(key) else {
|
||||||
|
throw ParseError.peerHasUnrecognizedKey(keyWithCase)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if lowercasedLine != "[interface]" && lowercasedLine != "[peer]" {
|
||||||
|
throw ParseError.invalidLine(line)
|
||||||
}
|
}
|
||||||
let interfaceSectionKeys: Set<String> = ["privatekey", "listenport", "address", "dns", "mtu"]
|
|
||||||
let peerSectionKeys: Set<String> = ["publickey", "presharedkey", "allowedips", "endpoint", "persistentkeepalive"]
|
|
||||||
if parserState == .inInterfaceSection {
|
|
||||||
guard interfaceSectionKeys.contains(key) else {
|
|
||||||
throw ParseError.interfaceHasUnrecognizedKey(keyWithCase)
|
|
||||||
}
|
|
||||||
} else if parserState == .inPeerSection {
|
|
||||||
guard peerSectionKeys.contains(key) else {
|
|
||||||
throw ParseError.peerHasUnrecognizedKey(keyWithCase)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if lowercasedLine != "[interface]" && lowercasedLine != "[peer]" {
|
|
||||||
throw ParseError.invalidLine(line)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let isLastLine = lineIndex == lines.count - 1
|
let isLastLine = lineIndex == lines.count - 1
|
||||||
|
Loading…
Reference in New Issue
Block a user