Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.5] bpo-41004: Resolve hash collisions for IPv4Interface and IPv6In… #21233

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

Merged
merged 3 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ def __lt__(self, other):
return False

def __hash__(self):
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
return hash((self._ip, self._prefixlen, int(self.network.network_address)))

__reduce__ = _IPAddressBase.__reduce__

Expand Down Expand Up @@ -2109,7 +2109,7 @@ def __lt__(self, other):
return False

def __hash__(self):
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
return hash((self._ip, self._prefixlen, int(self.network.network_address)))

__reduce__ = _IPAddressBase.__reduce__

Expand Down
11 changes: 11 additions & 0 deletions 11 Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,17 @@ def testsixtofour(self):
sixtofouraddr.sixtofour)
self.assertFalse(bad_addr.sixtofour)

# issue41004 Hash collisions in IPv4Interface and IPv6Interface
def testV4HashIsNotConstant(self):
ipv4_address1 = ipaddress.IPv4Interface("1.2.3.4")
ipv4_address2 = ipaddress.IPv4Interface("2.3.4.5")
self.assertNotEqual(ipv4_address1.__hash__(), ipv4_address2.__hash__())

# issue41004 Hash collisions in IPv4Interface and IPv6Interface
def testV6HashIsNotConstant(self):
ipv6_address1 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:1")
ipv6_address2 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:2")
self.assertNotEqual(ipv6_address1.__hash__(), ipv6_address2.__hash__())

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +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).
Morty Proxy This is a proxified and sanitized view of the page, visit original site.