Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
confconsole (2.2.3+keel16) trixie; urgency=low

* ipaddr.IP() refuses an integer outside 0 to 2**32-1 with
Error("ip out of range"). Before, IP(2**32) or IP(-1) was created and
only failed later in str() with a struct.error. IPRange computes its
broadcast address the same as before.

-- Nandika Gupta <nandika.g2@gmail.com> Tue, 06 Oct 2026 19:00:00 +0000

confconsole (2.2.3+keel15) trixie; urgency=low

* The Overlay network screen keeps one place in the Instance menu. It
Expand Down
5 changes: 4 additions & 1 deletion ipaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __new__(cls: Type["IP"], arg: AnyIP) -> "IP":
return int.__new__(cls, int(arg))

elif isinstance(arg, int):
if not 0 <= arg <= 0xFFFFFFFF:
raise Error(f"ip out of range ({arg})")

return int.__new__(cls, arg)

else:
Expand Down Expand Up @@ -89,7 +92,7 @@ def __init__(self, ip: AnyIP, netmask: AnyIP):
self.ip = IP(ip)
self.netmask = IP(netmask)
self.network = self.ip & self.netmask
self.broadcast = self.network + 2**32 - self.netmask - 1
self.broadcast = IP(int(self.network) + 2**32 - int(self.netmask) - 1)
self.cidr = int(32 - math.log(2**32 - self.netmask, 2))

def __contains__(self, ip: AnyIP) -> bool:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_ipaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def test_illegal_string_raises_error(self):
with pytest.raises(ipaddr.Error, match="illegal ip"):
IP("300.0.2.1")

@pytest.mark.parametrize("value", [0, 0xFFFFFFFF])
def test_int_at_the_ends_of_the_range(self, value):
assert int(IP(value)) == value

@pytest.mark.parametrize("value", [-1, 2**32])
def test_int_out_of_range_raises_error(self, value):
with pytest.raises(ipaddr.Error, match="ip out of range"):
IP(value)

def test_operator_past_the_last_address_raises_error(self):
with pytest.raises(ipaddr.Error, match="ip out of range"):
IP("255.255.255.255") + 1

@pytest.mark.parametrize(
"op, operand, expected",
[
Expand Down
Loading