fix: lib.net.cidr.host performs type-appropriate bounds check

This commit is contained in:
Sophie Taylor 2025-04-19 11:05:39 +10:00 committed by Sophie Taylor (spacekitteh)
parent 5cc4cb34fb
commit 12b9f46b00

View file

@ -67,9 +67,13 @@ in
i: n: i: n:
let let
cap = libNet.net.cidr.capacity n; cap = libNet.net.cidr.capacity n;
intCheck = builtins.isInt i -> (i >= (-cap) && i < cap);
ipCheck = libNet.net.types.ip.check i -> ((libNet.net.types.ip-in n).check result);
result = libNet.net.cidr.host i n;
in in
assert assertMsg (i >= (-cap) && i < cap) "The host ${toString i} lies outside of ${n}"; assert assertMsg (ipCheck && intCheck) "The host ${toString i} lies outside of ${n}";
libNet.net.cidr.host i n; result;
# hostCidr :: (ip | mac | integer) -> cidr -> cidr # hostCidr :: (ip | mac | integer) -> cidr -> cidr
# #
# Returns the nth host in the given cidr range (like cidr.host) # Returns the nth host in the given cidr range (like cidr.host)