]> granicus.if.org Git - python/commitdiff
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
authorChristian Heimes <christian@cheimes.de>
Fri, 15 Feb 2008 08:20:11 +0000 (08:20 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 15 Feb 2008 08:20:11 +0000 (08:20 +0000)
Thanks to Thomas Herve for the fix.

Lib/test/test_mmap.py
Misc/NEWS
Modules/mmapmodule.c

index 91d62754c08eb614184b4db275429b1d587c7118..2d87eadd2a593fd927ee93dd4c40b147cc61db6a 100644 (file)
@@ -426,6 +426,13 @@ class MmapTests(unittest.TestCase):
                 return mmap.mmap.__new__(klass, -1, *args, **kwargs)
         anon_mmap(PAGESIZE)
 
+    def test_prot_readonly(self):
+        mapsize = 10
+        open(TESTFN, "wb").write("a"*mapsize)
+        f = open(TESTFN, "rb")
+        m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
+        self.assertRaises(TypeError, m.write, "foo")
+
 
 def test_main():
     run_unittest(MmapTests)
index c4d64ceda6407253841d288ebb1f38afa70cbc0d..fdc81c1a539ae16871d6dd4b13530dead6435c3a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1142,6 +1142,8 @@ Library
 Extension Modules
 -----------------
 
+- Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
+
 - #2063: correct order of utime and stime in os.times() result on Windows.
 
 - Patch #1736: Fix file name handling of _msi.FCICreate.
index 49fe7f7c72c563461f0e35e3af2e86db8a73a3b9..e47211f171a20ebbd03f8cc47f26c667da8ebfba 100644 (file)
@@ -1122,6 +1122,10 @@ new_mmap_object(PyTypeObject *type, 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 */