Model: Cap networkPrefixLengths to valid values

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-10-29 16:49:49 +05:30
parent 1f8585443d
commit 3791b2e1b9
1 changed files with 7 additions and 1 deletions

View File

@ -28,7 +28,13 @@ extension IPAddressRange {
} }
let networkPrefixLengthSubstring = string[indexOfNetworkPrefixLength ..< string.endIndex] let networkPrefixLengthSubstring = string[indexOfNetworkPrefixLength ..< string.endIndex]
if let npl = UInt8(networkPrefixLengthSubstring) { 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 { } else {
return nil return nil
} }