Patch #2111: Avoid mmap segfault when modifying a PROT_READ block.

This commit is contained in:
Martin v. Löwis 2008-05-23 14:30:44 +00:00
parent 0812de63c2
commit 5212da1b96
3 changed files with 23 additions and 0 deletions

View File

@ -380,6 +380,23 @@ def test_both():
finally:
os.unlink(TESTFN)
# Test that setting access to PROT_READ gives exception
# rather than crashing
if hasattr(mmap, "PROT_READ"):
try:
mapsize = 10
open(TESTFN, "wb").write("a"*mapsize)
f = open(TESTFN, "rb")
m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
try:
m.write("foo")
except TypeError:
pass
else:
verify(0, "PROT_READ is not working")
finally:
os.unlink(TESTFN)
def test_anon():
print " anonymous mmap.mmap(-1, PAGESIZE)..."
m = mmap.mmap(-1, PAGESIZE)

View File

@ -86,6 +86,8 @@ Library
Extension Modules
-----------------
- Patch #2111: Avoid mmap segfault when modifying a PROT_READ block.
- zlib.decompressobj().flush(value) no longer crashes the interpreter when
passed a value less than or equal to zero.

View File

@ -881,6 +881,10 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
"mmap invalid access parameter.");
}
if (prot == PROT_READ) {
access = ACCESS_READ;
}
#ifdef HAVE_FSTAT
# ifdef __VMS
/* on OpenVMS we must ensure that all bytes are written to the file */