aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2023-12-01 07:16:49 -0800
committerGitHub <noreply@github.com>2023-12-01 15:16:49 +0000
commit0daf555c6fb3feba77989382135a58215e1d70a5 (patch)
tree0b7b09098b294c8406796e3851afe0ac00655c0b /Lib/test/test_socket.py
parent70a38ffb3d712f973eb17bd1bda541f238ae70d2 (diff)
downloadcpython-0daf555c6fb3feba77989382135a58215e1d70a5.tar.gz
cpython-0daf555c6fb3feba77989382135a58215e1d70a5.zip
bpo-37013: Fix the error handling in socket.if_indextoname() (GH-13503)
* Fix a crash when pass UINT_MAX. * Fix an integer overflow on 64-bit non-Windows platforms.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 86701caf053..4eb5af99d66 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -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.')