bpo-35989: Forbid a netmask > 32 for ipaddress.IPv4Network#11844
bpo-35989: Forbid a netmask > 32 for ipaddress.IPv4Network#11844matrixise wants to merge 3 commits into
Conversation
| 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.
This error message doesn't read well.
There was a problem hiding this comment.
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.
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. |
| 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.
| 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