-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-35989: Forbid a netmask > 32 for ipaddress.IPv4Network #11844
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
base: main
Are you sure you want to change the base?
Conversation
Lib/ipaddress.py
Outdated
mask = address[1] if len(address) > 1 else self._max_prefixlen | ||
if len(address) > 1: | ||
if isinstance(address[1], int) and 0 < address[1] > 32: | ||
raise NetmaskValueError("The netmask should be isn't valid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message doesn't read well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can be reworded and could include the max value (32) in the error so that users know the limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really strange, that was not my original message. Maybe a bad paste :/
@tirkarthi @jflorian maybe we could validate this PR and ping a core-dev. |
Lib/ipaddress.py
Outdated
@@ -1519,7 +1519,13 @@ def __init__(self, address, strict=True): | |||
# Constructing from a tuple (addr, [mask]) | |||
elif isinstance(address, tuple): | |||
addr = address[0] | |||
mask = address[1] if len(address) > 1 else self._max_prefixlen | |||
if len(address) > 1: | |||
if isinstance(address[1], int) and 0 < address[1] > 32: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(address[1], int) and 0 < address[1] > 32: | |
if isinstance(address[1], int) and address[1] > 32: |
if address
is larger than 32, it is larger than 0.
I have made the requested changes; please review again |
Thanks for making the requested changes! : please review the changes made to this pull request. |
I believe this is fixed in master with https://bugs.python.org/issue36845 and backported to 3.7 . ./python.exe
Python 3.8.0a4+ (heads/master:73934b9da0, May 18 2019, 17:28:10)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>> ipaddress.IPv4Network(('192.0.2.1', 33))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/ipaddress.py", line 1450, in __init__
self.netmask, self._prefixlen = self._make_netmask(mask)
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/ipaddress.py", line 1112, in _make_netmask
cls._report_invalid_netmask(prefixlen)
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/ipaddress.py", line 474, in _report_invalid_netmask
raise NetmaskValueError(msg) from None
ipaddress.NetmaskValueError: 33 is not a valid netmask |
Yes, this seems to have been fixed and is not an issue on master anymore:
|
hi all, I will follow this PR and the associated BPO. Thanks for the reminder. |
This PR is stale because it has been open for 30 days with no activity. |
https://bugs.python.org/issue35989