From 5a7d923e7561d6e2bd8ad505178efa2d27ebd785 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 6 Sep 2016 17:58:25 -0700 Subject: [PATCH] make sure to not call memcpy with a NULL second argument --- Objects/listobject.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index d688179d6b4..815a1b9ea2d 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -634,14 +634,17 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) item = a->ob_item; /* recycle the items that we are about to remove */ s = norig * sizeof(PyObject *); - if (s > sizeof(recycle_on_stack)) { - recycle = (PyObject **)PyMem_MALLOC(s); - if (recycle == NULL) { - PyErr_NoMemory(); - goto Error; + /* If norig == 0, item might be NULL, in which case we may not memcpy from it. */ + if (s) { + if (s > sizeof(recycle_on_stack)) { + recycle = (PyObject **)PyMem_MALLOC(s); + if (recycle == NULL) { + PyErr_NoMemory(); + goto Error; + } } + memcpy(recycle, &item[ilow], s); } - memcpy(recycle, &item[ilow], s); if (d < 0) { /* Delete -d items */ Py_ssize_t tail;