mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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.
This commit is contained in:
parent
d6b3e78504
commit
b3687ad454
2 changed files with 31 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue