summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-11-19 08:08:42 (GMT)
committerGitHub <noreply@github.com>2024-11-19 08:08:42 (GMT)
commitb3687ad454c4ac54c8599a10f3ace8a13ca48915 (patch)
treec11880ac43bd1d01d386c16fe1af8f3fae793b32 /Modules
parentd6b3e78504b3168c432b20002dbcf8ec9a435e61 (diff)
downloadcpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.zip
cpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.tar.gz
cpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.tar.bz2
gh-126876: Fix socket internal_select() for large timeout (#126968)
If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path. Add an unit test.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 2764bd6..06be822 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -810,7 +810,9 @@ internal_select(PySocketSockObject *s, int writing, PyTime_t interval,
/* s->sock_timeout is in seconds, timeout in ms */
ms = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_CEILING);
- assert(ms <= INT_MAX);
+ if (ms > INT_MAX) {
+ ms = INT_MAX;
+ }
/* On some OSes, typically BSD-based ones, the timeout parameter of the
poll() syscall, when negative, must be exactly INFTIM, where defined,
@@ -822,6 +824,7 @@ internal_select(PySocketSockObject *s, int writing, PyTime_t interval,
ms = -1;
#endif
}
+ assert(INT_MIN <= ms && ms <= INT_MAX);
Py_BEGIN_ALLOW_THREADS;
n = poll(&pollfd, 1, (int)ms);