Use long_range function for IPv6Network hosts() function

Previous implementation used xrange, which requires that the range
fit in a C long data type. Given that an IPv6 subnet is massive,
the ``salt.ext.ipadress.IPv6Network.hosts()`` function would stacktrace
with an OverflowError due to the use of xrange. However, ``/64`` is a
common netmask.

This PR uses the ``long_range`` function for the ``IPv6Network.hosts()``
function instead of ``xrange``.

While the funciton will no longer stacktrace on large IPv6 subnets, the user
should be aware that these large subnets will take a very long time to list.

Fixes #42166
This commit is contained in:
rallytime 2017-07-06 15:03:54 -06:00
parent 778ed74103
commit 11862743c2

View file

@ -28,9 +28,6 @@ bytes = bytearray
# Python 2 does not support exception chaining.
# s/ from None$//
# Python 2 ranges need to fit in a C long
# 'fix' hosts() for IPv6Network
# When checking for instances of int, also allow Python 2's long.
_builtin_isinstance = isinstance
@ -2259,7 +2256,7 @@ class IPv6Network(_BaseV6, _BaseNetwork):
"""
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in range(1, broadcast - network + 1):
for x in long_range(1, broadcast - network + 1):
yield self._address_class(network + x)
@property