-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipaddres.IPv4Network and ipaddress.IPv6Network tuple construction will accept out of valid range prefixlen #81026
Comments
When using the tuple-form of constructing IPv4Network and IPv6Network will accept prefixlen outside of the normal allowed ranges. Example:
>>> import ipaddress
>>> ipaddress.IPv4Network(('172.21.1.0', 400))
IPv4Network('172.21.1.0/400')
If given a negative number, it will error but not with a particularly useful error:
>>> x = ipaddress.IPv4Network(('172.21.1.0', -1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.7/ipaddress.py", line 1532, in __init__
self.netmask, self._prefixlen = self._make_netmask(mask)
File "/usr/lib64/python3.7/ipaddress.py", line 1112, in _make_netmask
netmask = IPv4Address(cls._ip_int_from_prefix(prefixlen))
File "/usr/lib64/python3.7/ipaddress.py", line 444, in _ip_int_from_prefix
return cls._ALL_ONES ^ (cls._ALL_ONES >> prefixlen)
ValueError: negative shift count Looking at the code, I think all that is needed is a range check within the respective _make_netmask methods in _BaseV4 and _BaseV6 classes |
Would you like to submit a fix, Nicolai? |
I'd be happy too. Would be a first time contribution though, so need to give me some time to figure my way around the process. |
There are some guidelines available at https://devguide.python.org/pullrequest/ |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: