[Python-checkins] python/dist/src/Modules mmapmodule.c,2.40,2.41

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Thu, 05 Sep 2002 14:48:08 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv29682/Modules

Modified Files:
	mmapmodule.c 
Log Message:
SF bug # 585792, Invalid mmap crashes Python interpreter

Raise ValueError if user passes a size to mmap which is larger
than the file.


Index: mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.40
retrieving revision 2.41
diff -C2 -d -r2.40 -r2.41
*** mmapmodule.c	23 Jul 2002 06:31:13 -0000	2.40
--- mmapmodule.c	5 Sep 2002 21:48:05 -0000	2.41
***************
*** 851,854 ****
--- 851,857 ----
  new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
  {
+ #ifdef HAVE_FSTAT
+ 	struct stat st;
+ #endif
  	mmap_object *m_obj;
  	PyObject *map_size_obj = NULL;
***************
*** 891,895 ****
  				    "mmap invalid access parameter.");
  	}
! 	
  	m_obj = PyObject_New (mmap_object, &mmap_object_type);
  	if (m_obj == NULL) {return NULL;}
--- 894,905 ----
  				    "mmap invalid access parameter.");
  	}
! 
! #ifdef HAVE_FSTAT
! 	if (fstat(fd, &st) == 0 && (size_t)map_size > st.st_size) {
! 		PyErr_SetString(PyExc_ValueError, 
! 				"mmap length is greater than file size");
! 		return NULL;
! 	}
! #endif
  	m_obj = PyObject_New (mmap_object, &mmap_object_type);
  	if (m_obj == NULL) {return NULL;}