From: Benjamin Peterson Date: Wed, 7 Sep 2016 00:58:25 +0000 (-0700) Subject: make sure to not call memcpy with a NULL second argument X-Git-Tag: v2.7.13rc1~166 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4d79003073a70e35fa7fd7f6d0eee7b95b6aed3;p=python make sure to not call memcpy with a NULL second argument --- diff --git a/Objects/listobject.c b/Objects/listobject.c index c414620151..8ee86c6413 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -669,14 +669,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 */ memmove(&item[ihigh+d], &item[ihigh],