diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-31 20:43:56 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-31 20:43:56 (GMT) |
commit | 2ca15013ec4fe77490e3205cd9ed8f9138f786fe (patch) | |
tree | 5acec25ceb5391bb772aa2246d184449c7c0755f | |
parent | 33413cbf5ead3de21064a39d162df14dae68231c (diff) | |
download | cpython-2ca15013ec4fe77490e3205cd9ed8f9138f786fe.zip cpython-2ca15013ec4fe77490e3205cd9ed8f9138f786fe.tar.gz cpython-2ca15013ec4fe77490e3205cd9ed8f9138f786fe.tar.bz2 |
Merged revisions 70879 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70879 | hirokazu.yamamoto | 2009-04-01 05:14:04 +0900 | 1 line
Issue #5387: Fixed mmap.move crash by integer overflow. (take2)
........
-rw-r--r-- | Lib/test/test_mmap.py | 20 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 2e03673..a2e9f72 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,7 +1,7 @@ from test.support import TESTFN, run_unittest import mmap import unittest -import os, re +import os, re, itertools PAGESIZE = mmap.PAGESIZE @@ -347,9 +347,21 @@ class MmapTests(unittest.TestCase): self.assertEqual(m[:], expected) m.close() - # should not crash - m = mmap.mmap(-1, 1) - self.assertRaises(ValueError, m.move, 1, 1, -1) + # segfault test (Issue 5387) + m = mmap.mmap(-1, 100) + offsets = [-100, -1, 0, 1, 100] + for source, dest, size in itertools.product(offsets, offsets, offsets): + try: + m.move(source, dest, size) + except ValueError: + pass + self.assertRaises(ValueError, m.move, -1, -1, -1) + self.assertRaises(ValueError, m.move, -1, -1, 0) + self.assertRaises(ValueError, m.move, -1, 0, -1) + self.assertRaises(ValueError, m.move, 0, -1, -1) + self.assertRaises(ValueError, m.move, -1, 0, 0) + self.assertRaises(ValueError, m.move, 0, -1, 0) + self.assertRaises(ValueError, m.move, 0, 0, -1) m.close() def test_anonymous(self): diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c6c8a30..b9c46cd 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -628,7 +628,7 @@ mmap_move_method(mmap_object *self, PyObject *args) } else { /* bounds check the values */ unsigned long pos = src > dest ? src : dest; - if (self->size >= pos && count > self->size - pos) { + if (self->size < pos || count > self->size - pos) { PyErr_SetString(PyExc_ValueError, "source or destination out of range"); return NULL; |