[Patches] fix Sleep() overflow condition in time module

Trent Mick trentm@activestate.com
Thu, 1 Jun 2000 19:33:13 -0700


Discussion:

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.


Legal:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.


Patch (use 'patch -p8'):

*** /home/trentm/main/contrib/python/dist/src/Modules/timemodule.c	Thu Jun  1 18:49:40 2000
--- /home/trentm/main/Apps/Perlium/Python/dist/src/Modules/timemodule.c	Wed May 31 23:54:18 2000
***************
*** 835,844 ****
  	}
  #else /* !MSDOS */
  #ifdef MS_WIN32
! 	/* XXX Can't interrupt this sleep */
! 	Py_BEGIN_ALLOW_THREADS
! 	Sleep((int)(secs*1000));
! 	Py_END_ALLOW_THREADS
  #else /* !MS_WIN32 */
  #ifdef PYOS_OS2
  	/* This Sleep *IS* Interruptable by Exceptions */
--- 835,851 ----
  	}
  #else /* !MSDOS */
  #ifdef MS_WIN32
! 	{
! 		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 */


-- 
Trent Mick
trentm@activestate.com