diff options
author | Fred Drake <fdrake@acm.org> | 2000-06-29 21:31:02 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-06-29 21:31:02 (GMT) |
commit | 0e12395190a54ce91fdc37593601f481cfcf3e70 (patch) | |
tree | bf2d3260ad661e1fc0b13647a4a581151ece4b1b /Modules/timemodule.c | |
parent | 699f352fb220d2e37247144081f7a11cc1dc365d (diff) | |
download | cpython-0e12395190a54ce91fdc37593601f481cfcf3e70.zip cpython-0e12395190a54ce91fdc37593601f481cfcf3e70.tar.gz cpython-0e12395190a54ce91fdc37593601f481cfcf3e70.tar.bz2 |
Trent Mick <trentm@activestate.com>:
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.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index fa7a635..cebcc68 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -835,10 +835,17 @@ floatsleep(double secs) } #else /* !MSDOS */ #ifdef MS_WIN32 - /* XXX Can't interrupt this sleep */ - Py_BEGIN_ALLOW_THREADS - Sleep((int)(secs*1000)); - Py_END_ALLOW_THREADS + { + double millisecs = secs * 1000.0; + if (millisecs > (double)ULONG_MAX) { + PyErr_SetString(PyExc_OverflowError, "sleep length is too large"); + return -1; + } + /* XXX Can't interrupt this sleep */ + Py_BEGIN_ALLOW_THREADS + Sleep((unsigned long)millisecs); + Py_END_ALLOW_THREADS + } #else /* !MS_WIN32 */ #ifdef PYOS_OS2 /* This Sleep *IS* Interruptable by Exceptions */ |