Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1baac72

Browse files
committed
Fix SF #441664: Python crash on del of a slice of a mmap
Check for slice/item deletion, which calls slice/item assignment with a NULL value, and raise a TypeError instead of coredumping. Bugreport and suggested fix by Alex Martelli.
1 parent 687a17d commit 1baac72

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Modules/mmapmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ mmap_ass_slice(mmap_object *self, int ilow, int ihigh, PyObject *v)
663663
else if ((size_t)ihigh > self->size)
664664
ihigh = self->size;
665665

666+
if (v == NULL) {
667+
PyErr_SetString(PyExc_TypeError,
668+
"mmap object doesn't support slice deletion");
669+
return -1;
670+
}
666671
if (! (PyString_Check(v)) ) {
667672
PyErr_SetString(PyExc_IndexError,
668673
"mmap slice assignment must be a string");
@@ -688,6 +693,11 @@ mmap_ass_item(mmap_object *self, int i, PyObject *v)
688693
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
689694
return -1;
690695
}
696+
if (v == NULL) {
697+
PyErr_SetString(PyExc_TypeError,
698+
"mmap object doesn't support item deletion");
699+
return -1;
700+
}
691701
if (! (PyString_Check(v) && PyString_Size(v)==1) ) {
692702
PyErr_SetString(PyExc_IndexError,
693703
"mmap assignment must be single-character string");

0 commit comments

Comments
 (0)