[Python-checkins] CVS: python/dist/src/Modules selectmodule.c,2.32,2.33

Guido van Rossum python-dev@python.org
Wed, 28 Jun 2000 14:18:15 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv3478

Modified Files:
	selectmodule.c 
Log Message:
Trent Mick:

This patches fixes a possible overflow of the optional timeout
parameter for the select() function (selectmodule.c). This timeout is
passed in as a double and then truncated to an int. If the double is
sufficiently large you can get unexpected results as it
overflows. This patch raises an overflow if the given select timeout
overflows.

[GvR: To my embarrassment, the original code was assuming an int could
always hold a million.  Note that the overflow check doesn't test for
a very large *negative* timeout passed in -- but who in the world
would do such a thing?]


Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.32
retrieving revision 2.33
diff -C2 -r2.32 -r2.33
*** selectmodule.c	2000/05/03 23:44:33	2.32
--- selectmodule.c	2000/06/28 21:18:13	2.33
***************
*** 239,243 ****
  	double timeout;
  	struct timeval tv, *tvp;
! 	int seconds;
  	int imax, omax, emax, max;
  	int n;
--- 239,243 ----
  	double timeout;
  	struct timeval tv, *tvp;
! 	long seconds;
  	int imax, omax, emax, max;
  	int n;
***************
*** 256,263 ****
  	}
  	else {
! 		seconds = (int)timeout;
  		timeout = timeout - (double)seconds;
  		tv.tv_sec = seconds;
! 		tv.tv_usec = (int)(timeout*1000000.0);
  		tvp = &tv;
  	}
--- 256,267 ----
  	}
  	else {
! 		if (timeout > (double)LONG_MAX) {
! 			PyErr_SetString(PyExc_OverflowError, "timeout period too long");
! 			return NULL;
! 		}
! 		seconds = (long)timeout;
  		timeout = timeout - (double)seconds;
  		tv.tv_sec = seconds;
! 		tv.tv_usec = (long)(timeout*1000000.0);
  		tvp = &tv;
  	}