From b67acaccff1b587717c1fc444179307da4919c12 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 23 Dec 2020 14:06:26 +0100 Subject: [PATCH] Kit: do not crash on [abcd::] with missing port Signed-off-by: Jason A. Donenfeld --- Sources/WireGuardKit/Endpoint.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/WireGuardKit/Endpoint.swift b/Sources/WireGuardKit/Endpoint.swift index d86290f..8454d87 100644 --- a/Sources/WireGuardKit/Endpoint.swift +++ b/Sources/WireGuardKit/Endpoint.swift @@ -52,6 +52,7 @@ extension Endpoint { let startOfHost = string.index(after: string.startIndex) guard let endOfHost = string.dropFirst().firstIndex(of: "]") else { return nil } let afterEndOfHost = string.index(after: endOfHost) + if afterEndOfHost == string.endIndex { return nil } guard string[afterEndOfHost] == ":" else { return nil } startOfPort = string.index(after: afterEndOfHost) hostString = String(string[startOfHost ..< endOfHost])