mirror of
https://github.com/python/cpython.git
synced 2025-08-11 20:40:27 +00:00
[3.12] bpo-37013: Fix the error handling in socket.if_indextoname() (GH-13503) (GH-112597)
* Fix a crash when pass UINT_MAX.
* Fix an integer overflow on 64-bit non-Windows platforms.
(cherry picked from commit 0daf555c6f
)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
parent
bdad5c367f
commit
fc7e67f51a
3 changed files with 31 additions and 9 deletions
|
@ -1082,7 +1082,20 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
'socket.if_indextoname() not available.')
|
||||
def testInvalidInterfaceIndexToName(self):
|
||||
self.assertRaises(OSError, socket.if_indextoname, 0)
|
||||
self.assertRaises(OverflowError, socket.if_indextoname, -1)
|
||||
self.assertRaises(OverflowError, socket.if_indextoname, 2**1000)
|
||||
self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF')
|
||||
if hasattr(socket, 'if_nameindex'):
|
||||
indices = dict(socket.if_nameindex())
|
||||
for index in indices:
|
||||
index2 = index + 2**32
|
||||
if index2 not in indices:
|
||||
with self.assertRaises((OverflowError, OSError)):
|
||||
socket.if_indextoname(index2)
|
||||
for index in 2**32-1, 2**64-1:
|
||||
if index not in indices:
|
||||
with self.assertRaises((OverflowError, OSError)):
|
||||
socket.if_indextoname(index)
|
||||
|
||||
@unittest.skipUnless(hasattr(socket, 'if_nametoindex'),
|
||||
'socket.if_nametoindex() not available.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue