From 3791b2e1b98eb4afd21c3deaf58a1f2abf325613 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 29 Oct 2018 16:49:49 +0530 Subject: [PATCH] Model: Cap networkPrefixLengths to valid values Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/Model/IPAddressRange.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WireGuard/WireGuard/Model/IPAddressRange.swift b/WireGuard/WireGuard/Model/IPAddressRange.swift index 3de30e5..c7e6be5 100644 --- a/WireGuard/WireGuard/Model/IPAddressRange.swift +++ b/WireGuard/WireGuard/Model/IPAddressRange.swift @@ -28,7 +28,13 @@ extension IPAddressRange { } let networkPrefixLengthSubstring = string[indexOfNetworkPrefixLength ..< string.endIndex] if let npl = UInt8(networkPrefixLengthSubstring) { - networkPrefixLength = npl + if (address is IPv4Address) { + networkPrefixLength = min(npl, 32) + } else if (address is IPv6Address) { + networkPrefixLength = min(npl, 128) + } else { + fatalError() + } } else { return nil }