From 12b9f46b001cf2e50f87e60274ad56e6a872a0f4 Mon Sep 17 00:00:00 2001 From: Sophie Taylor Date: Sat, 19 Apr 2025 11:05:39 +1000 Subject: [PATCH] fix: lib.net.cidr.host performs type-appropriate bounds check --- lib/net.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/net.nix b/lib/net.nix index 77fd0f5..41ee4f1 100644 --- a/lib/net.nix +++ b/lib/net.nix @@ -67,9 +67,13 @@ in i: n: let 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 - assert assertMsg (i >= (-cap) && i < cap) "The host ${toString i} lies outside of ${n}"; - libNet.net.cidr.host i n; + assert assertMsg (ipCheck && intCheck) "The host ${toString i} lies outside of ${n}"; + result; # hostCidr :: (ip | mac | integer) -> cidr -> cidr # # Returns the nth host in the given cidr range (like cidr.host)