summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/socketmodule.c
diff options
context:
space:
mode:
authorAlexSm <[email protected]>2024-02-12 10:25:32 +0100
committerGitHub <[email protected]>2024-02-12 10:25:32 +0100
commit12610a7bf38a4f1215aeb6eeea5e27e271c17e50 (patch)
treefce5b3816c5d68d91d7f1f6617c65b04e92f79a9 /contrib/tools/python3/src/Modules/socketmodule.c
parentb314cf4cbae67afc30e1f9c2f14047de0ad996cb (diff)
parent6a0655781d6103303eed0d377c3fb0955e468b5b (diff)
Merge pull request #1777 from alexv-smirnov/mergelibs13
Library import 13
Diffstat (limited to 'contrib/tools/python3/src/Modules/socketmodule.c')
-rw-r--r--contrib/tools/python3/src/Modules/socketmodule.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/contrib/tools/python3/src/Modules/socketmodule.c b/contrib/tools/python3/src/Modules/socketmodule.c
index 997df43f20c..f0c9b4691c1 100644
--- a/contrib/tools/python3/src/Modules/socketmodule.c
+++ b/contrib/tools/python3/src/Modules/socketmodule.c
@@ -6943,17 +6943,23 @@ Returns the interface index corresponding to the interface name if_name.");
static PyObject *
socket_if_indextoname(PyObject *self, PyObject *arg)
{
+ unsigned long index_long = PyLong_AsUnsignedLong(arg);
+ if (index_long == (unsigned long) -1 && PyErr_Occurred()) {
+ return NULL;
+ }
+
#ifdef MS_WINDOWS
- NET_IFINDEX index;
+ NET_IFINDEX index = (NET_IFINDEX)index_long;
#else
- unsigned long index;
+ unsigned int index = (unsigned int)index_long;
#endif
- char name[IF_NAMESIZE + 1];
- index = PyLong_AsUnsignedLong(arg);
- if (index == (unsigned long) -1)
+ if ((unsigned long)index != index_long) {
+ PyErr_SetString(PyExc_OverflowError, "index is too large");
return NULL;
+ }
+ char name[IF_NAMESIZE + 1];
if (if_indextoname(index, name) == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;