summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2002-09-05 22:30:03 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2002-09-05 22:30:03 (GMT)
commitdf4626fb8a003fdce8996fcdbefe1bba1f2a63cf (patch)
tree3a822ccf47a6cd88e268a36917761678f744b4c1 /Modules
parentba933e63a7746396eb27a97c9e1408fa0c5437cd (diff)
downloadcpython-df4626fb8a003fdce8996fcdbefe1bba1f2a63cf.zip
cpython-df4626fb8a003fdce8996fcdbefe1bba1f2a63cf.tar.gz
cpython-df4626fb8a003fdce8996fcdbefe1bba1f2a63cf.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/mmapmodule.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 5bad8e4..cabb860 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -850,6 +850,9 @@ _GetMapSize(PyObject *o)
static PyObject *
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;
int map_size;
@@ -890,7 +893,14 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
return PyErr_Format(PyExc_ValueError,
"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;}
m_obj->size = (size_t) map_size;