Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Lib/test/test_mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,9 +907,10 @@ def test_resize_up_anonymous_mapping(self):

with mmap.mmap(-1, start_size) as m:
m[:] = data
if sys.platform.startswith(('linux', 'android')):
# Can't expand a shared anonymous mapping on Linux.
# See https://bugzilla.kernel.org/show_bug.cgi?id=8691
if sys.platform.startswith(('linux', 'android', 'netbsd')):
# Can't expand a shared anonymous mapping on Linux
# (see https://bugzilla.kernel.org/show_bug.cgi?id=8691)
# or NetBSD.
with self.assertRaises(ValueError):
m.resize(new_size)
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in :meth:`mmap.mmap.resize` on NetBSD when growing a shared
anonymous mapping. :meth:`!resize` now raises :exc:`ValueError` in this
case, as it already did on Linux.
7 changes: 5 additions & 2 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,13 @@ mmap_mmap_resize_impl(mmap_object *self, Py_ssize_t new_size)
#ifdef UNIX
void *newmap;

#ifdef __linux__
#if defined(__linux__) || defined(__NetBSD__)
// Linux mremap() refuses to grow a shared anonymous mapping, and
// NetBSD mremap() returns a mapping whose grown region is not backed,
// so accessing it crashes. Reject it here in both cases.
if (self->fd == -1 && !(self->flags & MAP_PRIVATE) && new_size > self->size) {
PyErr_Format(PyExc_ValueError,
"mmap: can't expand a shared anonymous mapping on Linux");
"mmap: can't expand a shared anonymous mapping");
return NULL;
}
#endif
Expand Down
Loading