[pypy-commit] pypy merge-2.7.2: CPython issue11391: Fix a mmap crasher

amauryfa noreply at buildbot.pypy.org
Sun Jan 22 19:23:34 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: merge-2.7.2
Changeset: r51651:9def34947826
Date: 2012-01-22 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/9def34947826/

Log:	CPython issue11391: Fix a mmap crasher

diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py
--- a/pypy/rlib/rmmap.py
+++ b/pypy/rlib/rmmap.py
@@ -625,13 +625,16 @@
             flags = MAP_PRIVATE
             prot = PROT_READ | PROT_WRITE
         elif access == _ACCESS_DEFAULT:
-            pass
+            # map prot to access type
+            if prot & PROT_READ and prot & PROT_WRITE:
+                pass  # _ACCESS_DEFAULT
+            elif prot & PROT_WRITE:
+                access = ACCESS_WRITE
+            else:
+                access = ACCESS_READ
         else:
             raise RValueError("mmap invalid access parameter.")
 
-        if prot == PROT_READ:
-            access = ACCESS_READ
-
         # check file size
         try:
             st = os.fstat(fd)
diff --git a/pypy/rlib/test/test_rmmap.py b/pypy/rlib/test/test_rmmap.py
--- a/pypy/rlib/test/test_rmmap.py
+++ b/pypy/rlib/test/test_rmmap.py
@@ -263,10 +263,23 @@
         f.flush()
         m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ)
         raises(RTypeError, m.write, "foo")
+        m.close()
+        f.close()
+
+    def test_write_without_protwrite(self):
+        if os.name == "nt":
+            skip("Needs PROT_WRITE")
+        f = open(self.tmpname + "l2", "w+")
+        f.write("foobar")
+        f.flush()
+        m = mmap.mmap(f.fileno(), 6, prot=~mmap.PROT_WRITE)
+        raises(RTypeError, m.write_byte, 'a')
+        raises(RTypeError, m.write, "foo")
+        m.close()
         f.close()
 
     def test_size(self):
-        f = open(self.tmpname + "l", "w+")
+        f = open(self.tmpname + "l3", "w+")
         
         f.write("foobar")
         f.flush()


More information about the pypy-commit mailing list