Commit 2ca15013 authored by Hirokazu Yamamoto's avatar Hirokazu Yamamoto

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)
........
parent 33413cbf
from test.support import TESTFN, run_unittest from test.support import TESTFN, run_unittest
import mmap import mmap
import unittest import unittest
import os, re import os, re, itertools
PAGESIZE = mmap.PAGESIZE PAGESIZE = mmap.PAGESIZE
...@@ -347,9 +347,21 @@ class MmapTests(unittest.TestCase): ...@@ -347,9 +347,21 @@ class MmapTests(unittest.TestCase):
self.assertEqual(m[:], expected) self.assertEqual(m[:], expected)
m.close() m.close()
# should not crash # segfault test (Issue 5387)
m = mmap.mmap(-1, 1) m = mmap.mmap(-1, 100)
self.assertRaises(ValueError, m.move, 1, 1, -1) 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() m.close()
def test_anonymous(self): def test_anonymous(self):
......
...@@ -628,7 +628,7 @@ mmap_move_method(mmap_object *self, PyObject *args) ...@@ -628,7 +628,7 @@ mmap_move_method(mmap_object *self, PyObject *args)
} else { } else {
/* bounds check the values */ /* bounds check the values */
unsigned long pos = src > dest ? src : dest; 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, PyErr_SetString(PyExc_ValueError,
"source or destination out of range"); "source or destination out of range");
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment