diff options
author | Zackery Spytz <zspytz@gmail.com> | 2023-12-01 07:16:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 15:16:49 +0000 |
commit | 0daf555c6fb3feba77989382135a58215e1d70a5 (patch) | |
tree | 0b7b09098b294c8406796e3851afe0ac00655c0b /Lib/test/test_socket.py | |
parent | 70a38ffb3d712f973eb17bd1bda541f238ae70d2 (diff) | |
download | cpython-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.py | 13 |
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.') |