]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
make sure to not call memcpy with a NULL second argument
authorBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 00:58:25 +0000 (17:58 -0700)
committerBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 00:58:25 +0000 (17:58 -0700)
Objects/listobject.c

index d688179d6b4d12340f8b6155c3c123409ee0cb7d..815a1b9ea2d80b17f8c015aa05abcd145c25b6bb 100644 (file)
@@ -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;