Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e12395

Browse files
committed
Trent Mick <[email protected]>:
This patch fixes a possible overflow in the Sleep system call on Win32/64 in the time_sleep() function in the time module. For very large values of the give time to sleep the number of milliseconds can overflow and give unexpected sleep intervals. THis patch raises an OverflowError if the value overflows. Closes SourceForge patch #100514.
1 parent 699f352 commit 0e12395

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Modules/timemodule.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,17 @@ floatsleep(double secs)
835835
}
836836
#else /* !MSDOS */
837837
#ifdef MS_WIN32
838-
/* XXX Can't interrupt this sleep */
839-
Py_BEGIN_ALLOW_THREADS
840-
Sleep((int)(secs*1000));
841-
Py_END_ALLOW_THREADS
838+
{
839+
double millisecs = secs * 1000.0;
840+
if (millisecs > (double)ULONG_MAX) {
841+
PyErr_SetString(PyExc_OverflowError, "sleep length is too large");
842+
return -1;
843+
}
844+
/* XXX Can't interrupt this sleep */
845+
Py_BEGIN_ALLOW_THREADS
846+
Sleep((unsigned long)millisecs);
847+
Py_END_ALLOW_THREADS
848+
}
842849
#else /* !MS_WIN32 */
843850
#ifdef PYOS_OS2
844851
/* This Sleep *IS* Interruptable by Exceptions */

0 commit comments

Comments
 (0)