summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-10-05 02:27:32 (GMT)
committerGitHub <noreply@github.com>2024-10-05 02:27:32 (GMT)
commita5fc50994a3fae46d0c3d496c4e1d5e00548a1b8 (patch)
treebbc2f94f94891ec47019311105f6e51ea6cde9c0
parentadfe7657a3f1ce5d8384694ed27a40376a18fa6c (diff)
downloadcpython-a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8.zip
cpython-a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8.tar.gz
cpython-a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8.tar.bz2
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)
* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait * Address code review * nit
-rw-r--r--Python/parking_lot.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/parking_lot.c b/Python/parking_lot.c
index 841b1d7..a7e9760 100644
--- a/Python/parking_lot.c
+++ b/Python/parking_lot.c
@@ -102,7 +102,14 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
millis = INFINITE;
}
else {
- millis = (DWORD) (timeout / 1000000);
+ PyTime_t div = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_TIMEOUT);
+ // Prevent overflow with clamping the result
+ if ((PyTime_t)PY_DWORD_MAX < div) {
+ millis = PY_DWORD_MAX;
+ }
+ else {
+ millis = (DWORD) div;
+ }
}
wait = WaitForSingleObjectEx(sema->platform_sem, millis, FALSE);
if (wait == WAIT_OBJECT_0) {