pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/a6f73f61147048187908299ae911c5ad498d813a

8faa60c69660fa.css" /> [3.9] bpo-37013: Fix the error handling in socket.if_indextoname() (G… · python/cpython@a6f73f6 · GitHub
Skip to content

Commit a6f73f6

Browse files
[3.9] bpo-37013: Fix the error handling in socket.if_indextoname() (GH-13503) (GH-112600)
* Fix a crash when pass UINT_MAX. * Fix an integer overflow on 64-bit non-Windows platforms. (cherry picked from commit 0daf555) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 75da506 commit a6f73f6

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lib/test/test_socket.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,20 @@ def testInterfaceNameIndex(self):
10701070
'socket.if_indextoname() not available.')
10711071
def testInvalidInterfaceIndexToName(self):
10721072
self.assertRaises(OSError, socket.if_indextoname, 0)
1073+
self.assertRaises(OverflowError, socket.if_indextoname, -1)
1074+
self.assertRaises(OverflowError, socket.if_indextoname, 2**1000)
10731075
self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF')
1076+
if hasattr(socket, 'if_nameindex'):
1077+
indices = dict(socket.if_nameindex())
1078+
for index in indices:
1079+
index2 = index + 2**32
1080+
if index2 not in indices:
1081+
with self.assertRaises((OverflowError, OSError)):
1082+
socket.if_indextoname(index2)
1083+
for index in 2**32-1, 2**64-1:
1084+
if index not in indices:
1085+
with self.assertRaises((OverflowError, OSError)):
1086+
socket.if_indextoname(index)
10741087

10751088
@unittest.skipUnless(hasattr(socket, 'if_nametoindex'),
10761089
'socket.if_nametoindex() not available.')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash in :func:`socket.if_indextoname` with specific value (UINT_MAX).
2+
Fix an integer overflow in :func:`socket.if_indextoname` on 64-bit
3+
non-Windows platforms.

Modules/socketmodule.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6890,17 +6890,23 @@ Returns the interface index corresponding to the interface name if_name.");
68906890
static PyObject *
68916891
socket_if_indextoname(PyObject *self, PyObject *arg)
68926892
{
6893+
unsigned long index_long = PyLong_AsUnsignedLong(arg);
6894+
if (index_long == (unsigned long) -1 && PyErr_Occurred()) {
6895+
return NULL;
6896+
}
6897+
68936898
#ifdef MS_WINDOWS
6894-
NET_IFINDEX index;
6899+
NET_IFINDEX index = (NET_IFINDEX)index_long;
68956900
#else
6896-
unsigned long index;
6901+
unsigned int index = (unsigned int)index_long;
68976902
#endif
6898-
char name[IF_NAMESIZE + 1];
68996903

6900-
index = PyLong_AsUnsignedLong(arg);
6901-
if (index == (unsigned long) -1)
6904+
if ((unsigned long)index != index_long) {
6905+
PyErr_SetString(PyExc_OverflowError, "index is too large");
69026906
return NULL;
6907+
}
69036908

6909+
char name[IF_NAMESIZE + 1];
69046910
if (if_indextoname(index, name) == NULL) {
69056911
PyErr_SetFromErrno(PyExc_OSError);
69066912
return NULL;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy