Kit: do not crash on [abcd::] with missing port

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-12-23 14:06:26 +01:00
parent d8568b0e31
commit b67acaccff
1 changed files with 1 additions and 0 deletions

View File

@ -52,6 +52,7 @@ extension Endpoint {
let startOfHost = string.index(after: string.startIndex) let startOfHost = string.index(after: string.startIndex)
guard let endOfHost = string.dropFirst().firstIndex(of: "]") else { return nil } guard let endOfHost = string.dropFirst().firstIndex(of: "]") else { return nil }
let afterEndOfHost = string.index(after: endOfHost) let afterEndOfHost = string.index(after: endOfHost)
if afterEndOfHost == string.endIndex { return nil }
guard string[afterEndOfHost] == ":" else { return nil } guard string[afterEndOfHost] == ":" else { return nil }
startOfPort = string.index(after: afterEndOfHost) startOfPort = string.index(after: afterEndOfHost)
hostString = String(string[startOfHost ..< endOfHost]) hostString = String(string[startOfHost ..< endOfHost])