Model: Cap networkPrefixLengths to valid values

This commit is contained in:
Roopesh Chander 2018-10-29 16:49:49 +05:30
parent 93be31e4e6
commit 7498e9556b
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
} }