summaryrefslogtreecommitdiffstats
path: root/Lib/ipaddress.py
diff options
context:
space:
mode:
authorNicolai Moore <niconorsk@gmail.com>2019-05-14 10:32:59 (GMT)
committerInada Naoki <songofacandy@gmail.com>2019-05-14 10:32:59 (GMT)
commit5e48e3db6f5a937023e99d89cef8884d22bd8533 (patch)
treea3d3ca95253f60968046c87393d29a86b3ab7ca6 /Lib/ipaddress.py
parentf0be4bbb9b3cee876249c23f2ae6f38f43fa7495 (diff)
downloadcpython-5e48e3db6f5a937023e99d89cef8884d22bd8533.zip
cpython-5e48e3db6f5a937023e99d89cef8884d22bd8533.tar.gz
cpython-5e48e3db6f5a937023e99d89cef8884d22bd8533.tar.bz2
bpo-36845: validate integer network prefix when constructing IP networks (GH-13298)
Diffstat (limited to 'Lib/ipaddress.py')
-rw-r--r--Lib/ipaddress.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index 662d737..873c764 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -1108,6 +1108,8 @@ class _BaseV4:
if arg not in cls._netmask_cache:
if isinstance(arg, int):
prefixlen = arg
+ if not (0 <= prefixlen <= cls._max_prefixlen):
+ cls._report_invalid_netmask(prefixlen)
else:
try:
# Check for a netmask in prefix length form
@@ -1538,6 +1540,8 @@ class _BaseV6:
if arg not in cls._netmask_cache:
if isinstance(arg, int):
prefixlen = arg
+ if not (0 <= prefixlen <= cls._max_prefixlen):
+ cls._report_invalid_netmask(prefixlen)
else:
prefixlen = cls._prefix_from_prefix_string(arg)
netmask = IPv6Address(cls._ip_int_from_prefix(prefixlen))