]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 70879 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 31 Mar 2009 20:22:13 +0000 (20:22 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 31 Mar 2009 20:22:13 +0000 (20:22 +0000)
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)
........

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

index a73dfedaa3cdec57fa9620e8d68c01c8f203592e..5506956eb65817cc1bf346b9bc707b2c622936fa 100644 (file)
@@ -1,7 +1,7 @@
 from test.test_support import TESTFN, run_unittest
 import mmap
 import unittest
-import os, re
+import os, re, itertools
 
 PAGESIZE = mmap.PAGESIZE
 
@@ -350,9 +350,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):
index bd7f7cc8889037531c0d93cffb8ccf6629b4d621..cbacc2fc25222bcd5a20d739d43731d907286ca6 100644 (file)
@@ -617,7 +617,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;