diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-09-07 00:58:25 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-09-07 00:58:25 (GMT) |
commit | 5a7d923e7561d6e2bd8ad505178efa2d27ebd785 (patch) | |
tree | 8396c6508b17f6eb594c92bcd3e1bc3944606b7b /Objects/listobject.c | |
parent | 8c94f9746578fd9294f606d9d81e7fb466b34bdb (diff) | |
download | cpython-5a7d923e7561d6e2bd8ad505178efa2d27ebd785.zip cpython-5a7d923e7561d6e2bd8ad505178efa2d27ebd785.tar.gz cpython-5a7d923e7561d6e2bd8ad505178efa2d27ebd785.tar.bz2 |
make sure to not call memcpy with a NULL second argument
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index d688179..815a1b9 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; |