From 029df5d3292bad193a41c52e36c922fe48aeaa1e Mon Sep 17 00:00:00 2001 From: gmbnt Date: Thu, 2 Apr 2020 12:20:14 +1100 Subject: [PATCH] Guard against invalid path sizes --- .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index 1acf0ef20..63daf0a4b 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -191,6 +191,7 @@ internal enum OnionRequestAPI { /// Returns a `Path` to be used for building an onion request. Builds new paths as needed. private static func getPath() -> Promise { + guard pathSize >= 1 else { preconditionFailure("Cannot build path of size zero.") } // randomElement() uses the system's default random generator, which is cryptographically secure if paths.count >= pathCount { return Promise { $0.fulfill(paths.randomElement()!) }