Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit c78ad55

Browse files
author
Anselm Kruis
committed
Merge commit cfc7ff8 into branch 3.6-slp.
2 parents 46aaea7 + cfc7ff8 commit c78ad55

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

Include/patchlevel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define PY_RELEASE_SERIAL 0
2424

2525
/* Version as a string */
26-
#define PY_VERSION "3.6.11"
26+
#define PY_VERSION "3.6.11+"
2727
/*--end constants--*/
2828

2929
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.

Lib/ipaddress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ def __lt__(self, other):
14181418
return False
14191419

14201420
def __hash__(self):
1421-
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
1421+
return hash((self._ip, self._prefixlen, int(self.network.network_address)))
14221422

14231423
__reduce__ = _IPAddressBase.__reduce__
14241424

@@ -2092,7 +2092,7 @@ def __lt__(self, other):
20922092
return False
20932093

20942094
def __hash__(self):
2095-
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
2095+
return hash((self._ip, self._prefixlen, int(self.network.network_address)))
20962096

20972097
__reduce__ = _IPAddressBase.__reduce__
20982098

Lib/test/test_ipaddress.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,17 @@ def testsixtofour(self):
19901990
sixtofouraddr.sixtofour)
19911991
self.assertFalse(bad_addr.sixtofour)
19921992

1993+
# issue41004 Hash collisions in IPv4Interface and IPv6Interface
1994+
def testV4HashIsNotConstant(self):
1995+
ipv4_address1 = ipaddress.IPv4Interface("1.2.3.4")
1996+
ipv4_address2 = ipaddress.IPv4Interface("2.3.4.5")
1997+
self.assertNotEqual(ipv4_address1.__hash__(), ipv4_address2.__hash__())
1998+
1999+
# issue41004 Hash collisions in IPv4Interface and IPv6Interface
2000+
def testV6HashIsNotConstant(self):
2001+
ipv6_address1 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:1")
2002+
ipv6_address2 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:2")
2003+
self.assertNotEqual(ipv6_address1.__hash__(), ipv6_address2.__hash__())
19932004

19942005
if __name__ == '__main__':
19952006
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CVE-2020-14422: The __hash__() methods of ipaddress.IPv4Interface and ipaddress.IPv6Interface incorrectly generated constant hash values of 32 and 128 respectively. This resulted in always causing hash collisions. The fix uses hash() to generate hash values for the tuple of (address, mask length, network address).

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
This is Python version 3.6.11
2-
=============================
1+
This is Python version 3.6.11+
2+
==============================
33

44
.. image:: https://travis-ci.org/python/cpython.svg?branch=3.6
55
:alt: CPython build status on Travis CI

0 commit comments

Comments
 (0)