diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-12-03 14:12:59 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 14:12:59 (GMT) |
| commit | b49e902b81a0ead84e2002f94a2a2b2ae9b09ada (patch) | |
| tree | 36c9dfd49cc759e15effd584a8cee97bde312351 /Modules | |
| parent | c40656eeff64bd54bd13c7a146f0b140ffdfdf7b (diff) | |
| download | cpython-b49e902b81a0ead84e2002f94a2a2b2ae9b09ada.zip cpython-b49e902b81a0ead84e2002f94a2a2b2ae9b09ada.tar.gz cpython-b49e902b81a0ead84e2002f94a2a2b2ae9b09ada.tar.bz2 | |
[3.12] gh-126876: Fix socket internal_select() for large timeout (GH-126968) (#127003)
gh-126876: Fix socket internal_select() for large timeout (GH-126968)
If the timeout is larger than INT_MAX, replace it with INT_MAX, in
the poll() code path.
Add an unit test.
(cherry picked from commit b3687ad454c4ac54c8599a10f3ace8a13ca48915)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/socketmodule.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 9724879..7f2ebba 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -816,7 +816,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, @@ -828,6 +830,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); |
