diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-15 14:16:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-15 14:16:55 (GMT) |
commit | c5a6fb654a280c7b17f1d348e2e40d62ca04c5d3 (patch) | |
tree | 968e2057ace876fc7730e3c19849fa3036235a57 | |
parent | b39c78a73c203dcaf8f2061da81827c667440402 (diff) | |
download | cpython-c5a6fb654a280c7b17f1d348e2e40d62ca04c5d3.zip cpython-c5a6fb654a280c7b17f1d348e2e40d62ca04c5d3.tar.gz cpython-c5a6fb654a280c7b17f1d348e2e40d62ca04c5d3.tar.bz2 |
[3.5] bpo-29931 fix __lt__ check in ipaddress.ip_interface for both v4 and v6. (GH-879) (#2218)
the original logic was just comparing the network address
but this is wrong because if the network address is equal then
we need to compare the ip address for breaking the tie
add more ip_interface comparison tests.
(cherry picked from commit 7bd8d3e794782582a4ad1c9749424fff86802c3e)
-rw-r--r-- | Lib/ipaddress.py | 6 | ||||
-rw-r--r-- | Lib/test/test_ipaddress.py | 37 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 36 insertions, 10 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 1f90058..35ca38e 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1410,7 +1410,8 @@ class IPv4Interface(IPv4Address): if address_less is NotImplemented: return NotImplemented try: - return self.network < other.network + return (self.network < other.network or + self.network == other.network and address_less) except AttributeError: # We *do* allow addresses and interfaces to be sorted. The # unassociated address is considered less than all interfaces. @@ -2100,7 +2101,8 @@ class IPv6Interface(IPv6Address): if address_less is NotImplemented: return NotImplemented try: - return self.network < other.network + return (self.network < other.network or + self.network == other.network and address_less) except AttributeError: # We *do* allow addresses and interfaces to be sorted. The # unassociated address is considered less than all interfaces. diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 91ae8d8..e3dec87 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -1404,14 +1404,35 @@ class IpaddrUnitTest(unittest.TestCase): ipaddress.ip_address('::2')) def testInterfaceComparison(self): - self.assertTrue(ipaddress.ip_interface('1.1.1.1') <= - ipaddress.ip_interface('1.1.1.1')) - self.assertTrue(ipaddress.ip_interface('1.1.1.1') <= - ipaddress.ip_interface('1.1.1.2')) - self.assertTrue(ipaddress.ip_interface('::1') <= - ipaddress.ip_interface('::1')) - self.assertTrue(ipaddress.ip_interface('::1') <= - ipaddress.ip_interface('::2')) + self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') == + ipaddress.ip_interface('1.1.1.1/24')) + self.assertTrue(ipaddress.ip_interface('1.1.1.1/16') < + ipaddress.ip_interface('1.1.1.1/24')) + self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') < + ipaddress.ip_interface('1.1.1.2/24')) + self.assertTrue(ipaddress.ip_interface('1.1.1.2/16') < + ipaddress.ip_interface('1.1.1.1/24')) + self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') > + ipaddress.ip_interface('1.1.1.1/16')) + self.assertTrue(ipaddress.ip_interface('1.1.1.2/24') > + ipaddress.ip_interface('1.1.1.1/24')) + self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') > + ipaddress.ip_interface('1.1.1.2/16')) + + self.assertTrue(ipaddress.ip_interface('::1/64') == + ipaddress.ip_interface('::1/64')) + self.assertTrue(ipaddress.ip_interface('::1/64') < + ipaddress.ip_interface('::1/80')) + self.assertTrue(ipaddress.ip_interface('::1/64') < + ipaddress.ip_interface('::2/64')) + self.assertTrue(ipaddress.ip_interface('::2/48') < + ipaddress.ip_interface('::1/64')) + self.assertTrue(ipaddress.ip_interface('::1/80') > + ipaddress.ip_interface('::1/64')) + self.assertTrue(ipaddress.ip_interface('::2/64') > + ipaddress.ip_interface('::1/64')) + self.assertTrue(ipaddress.ip_interface('::1/64') > + ipaddress.ip_interface('::2/48')) def testNetworkComparison(self): # ip1 and ip2 have the same network address @@ -56,6 +56,9 @@ Extension Modules Library ------- +- bpo-29931: Fixed comparison check for ipaddress.ip_interface objects. + Patch by Sanjay Sundaresan. + - [Security] bpo-29591: Update expat copy from 2.1.1 to 2.2.0 to get fixes of CVE-2016-0718 and CVE-2016-4472. See https://sourceforge.net/p/expat/bugs/537/ for more information. |