Commit 3b4fff80 authored by Neal Norwitz's avatar Neal Norwitz

Fix SF bug #1402308, segfault when using mmap(-1, ...)

This didn't crash on Linux, but valgrind complained.
I'm not sure if this test is valid on Windows.

Will backport.
parent ae1df411
...@@ -31,6 +31,7 @@ test_mmap ...@@ -31,6 +31,7 @@ test_mmap
Modifying copy-on-write memory map. Modifying copy-on-write memory map.
Ensuring copy-on-write maps cannot be resized. Ensuring copy-on-write maps cannot be resized.
Ensuring invalid access parameter raises exception. Ensuring invalid access parameter raises exception.
Try opening a bad file descriptor...
Ensuring that passing 0 as map length sets map size to current file size. Ensuring that passing 0 as map length sets map size to current file size.
Ensuring that passing 0 as map length sets map size to current file size. Ensuring that passing 0 as map length sets map size to current file size.
Test passed Test passed
...@@ -281,6 +281,14 @@ def test_both(): ...@@ -281,6 +281,14 @@ def test_both():
except OSError: except OSError:
pass pass
print ' Try opening a bad file descriptor...'
try:
mmap.mmap(-1, 4096)
except mmap.error:
pass
else:
verify(0, 'expected a mmap.error but did not get it')
# Do a tougher .find() test. SF bug 515943 pointed out that, in 2.2, # Do a tougher .find() test. SF bug 515943 pointed out that, in 2.2,
# searching for data with embedded \0 bytes didn't work. # searching for data with embedded \0 bytes didn't work.
f = open(TESTFN, 'w+') f = open(TESTFN, 'w+')
......
...@@ -529,6 +529,7 @@ Michael Scharf ...@@ -529,6 +529,7 @@ Michael Scharf
Neil Schemenauer Neil Schemenauer
David Scherer David Scherer
Gregor Schmid Gregor Schmid
Ralf Schmitt
Peter Schneider-Kamp Peter Schneider-Kamp
Sam Schulenburg Sam Schulenburg
Stefan Schwarzer Stefan Schwarzer
......
...@@ -216,6 +216,8 @@ Core and builtins ...@@ -216,6 +216,8 @@ Core and builtins
Extension Modules Extension Modules
----------------- -----------------
- Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
- Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints. - Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.
Also fix ungetmouse() which did not accept arguments properly. Also fix ungetmouse() which did not accept arguments properly.
The code now conforms to the documented signature. The code now conforms to the documented signature.
......
...@@ -918,6 +918,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -918,6 +918,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
#endif #endif
m_obj = PyObject_New (mmap_object, &mmap_object_type); m_obj = PyObject_New (mmap_object, &mmap_object_type);
if (m_obj == NULL) {return NULL;} if (m_obj == NULL) {return NULL;}
m_obj->data = NULL;
m_obj->size = (size_t) map_size; m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0; m_obj->pos = (size_t) 0;
m_obj->fd = dup(fd); m_obj->fd = dup(fd);
......
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