Mailing List Archive

python/dist/src/Modules mmapmodule.c,2.35.6.2,2.35.6.3
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv12162/Modules

Modified Files:
Tag: release22-maint
mmapmodule.c
Log Message:
Backport of SF bug # 585792, Invalid mmap crashes Python interpreter

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

Also need Tim's fix in test_mmap.py, 1.22 which flushes the file
before mmap'ing it.



Index: mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.35.6.2
retrieving revision 2.35.6.3
diff -C2 -d -r2.35.6.2 -r2.35.6.3
*** mmapmodule.c 8 Mar 2002 13:40:07 -0000 2.35.6.2
--- mmapmodule.c 5 Sep 2002 22:30:03 -0000 2.35.6.3
***************
*** 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;}