fix: IP() refuses integers out of range #30
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Keel-Linux/confconsole!30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/ip-range"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up from #29, as suggested there.
IP() took any integer, so IP(2**32) or IP(-1) was created fine and only failed later in str() with a struct.error. It now raises Error("ip out of range") at construction, like the "illegal ip" error for bad strings.
IPRange built its broadcast address as
network + 2**32 - netmask - 1, which goes past 2**32 for a moment with IP's operators, so that line now does the maths on plain ints. Same result as before.Tests: 0 and 232-1 still work, -1 and 232 raise, and 255.255.255.255 + 1 raises. Full suite: 956 passed, ipaddr.py stays at 100%. Added a changelog entry (2.2.3+keel16).
Thanks @Nandika-Gupta, this is a clean follow-up.
I ran it: 956 passed,
ipaddr.pystays at 100%. The range check is right (0 to 232-1, both ends tested), and the error matches the existing "illegal ip" style. Good catch onIPRange.broadcast: with the new check, computingnetwork + 2**32 - netmask - 1throughIP's operators would overshoot 232 in the middle of the expression and raise, so doing it on plain ints is exactly the right fix. The test that255.255.255.255 + 1now raises is a nice touch too.A correction to something I wrote on #29: I said the network screens use
IPRangeto validate host addresses. I checked, and they don't:confconsole.pyonly usesipaddr.is_legal_ip, and the final network checks use Python's stdlibipaddress. SoIPandIPRangehave no runtime callers today, and this change can't break a screen. The strict<in__contains__is still worth documenting as you did, but my reason for it was wrong. Sorry about that.Approving; I'll merge.
Oh got it, thanks for clarifying! Glad the fix works.