]> granicus.if.org Git - python/commitdiff
Merge fix for issue #11391
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 6 Mar 2011 00:50:56 +0000 (01:50 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 6 Mar 2011 00:50:56 +0000 (01:50 +0100)
1  2 
Lib/test/test_mmap.py
Misc/NEWS
Modules/mmapmodule.c

index cbef37441dd48cdd1f268b31b4a023a92f22aa69,0822cc12c313975a45c02566365b44da4f3551c3..9b7100d7a29f66a5ab443b2dd0e6fb15d9edc152
@@@ -229,11 -231,20 +229,19 @@@ class MmapTests(unittest.TestCase)
  
          if os.name == "posix":
              # Try incompatible flags, prot and access parameters.
 -            f = open(TESTFN, "r+b")
 -            self.assertRaises(ValueError, mmap.mmap, f.fileno(), mapsize,
 -                              flags=mmap.MAP_PRIVATE,
 -                              prot=mmap.PROT_READ, access=mmap.ACCESS_WRITE)
 -            f.close()
 +            with open(TESTFN, "r+b") as f:
 +                self.assertRaises(ValueError, mmap.mmap, f.fileno(), mapsize,
 +                                  flags=mmap.MAP_PRIVATE,
 +                                  prot=mmap.PROT_READ, access=mmap.ACCESS_WRITE)
  
+             # Try writing with PROT_EXEC and without PROT_WRITE
+             prot = mmap.PROT_READ | getattr(mmap, 'PROT_EXEC', 0)
+             with open(TESTFN, "r+b") as f:
+                 m = mmap.mmap(f.fileno(), mapsize, prot=prot)
+                 self.assertRaises(TypeError, m.write, b"abcdef")
+                 self.assertRaises(TypeError, m.write_byte, 0)
+                 m.close()
      def test_bad_file_desc(self):
          # Try opening a bad file descriptor...
          self.assertRaises(mmap.error, mmap.mmap, -2, 4096)
diff --cc Misc/NEWS
index fcbcc882a97f53e1bf3eef18c5276987f7eb405b,9531d908c3111849591e5429fb6bc5907fe8fbb2..0b5b74b9377e96973c3c775a92ce8609d3356aed
+++ b/Misc/NEWS
@@@ -31,10 -37,10 +31,14 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #11391: Writing to a mmap object created with
+   ``mmap.PROT_READ|mmap.PROT_EXEC`` would segfault instead of raising a
+   TypeError.  Patch by Charles-François Natali.
 +- Issue #11306: mailbox in certain cases adapts to an inability to open
 +  certain files in read-write mode.  Previously it detected this by
 +  checking for EACCES, now it also checks for EROFS.
 +
  - Issue #11265: asyncore now correctly handles EPIPE, EBADF and EAGAIN errors
    on accept(), send() and recv().
  
Simple merge