[Python-checkins] cpython (3.5): make sure to not call memcpy with a NULL second argument

benjamin.peterson python-checkins at python.org
Tue Sep 6 20:59:10 EDT 2016


https://hg.python.org/cpython/rev/5f3f6f1fb73a
changeset:   103188:5f3f6f1fb73a
branch:      3.5
parent:      103182:1e61cc86df03
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Sep 06 17:58:25 2016 -0700
summary:
  make sure to not call memcpy with a NULL second argument

files:
  Objects/listobject.c |  15 +++++++++------
  1 files changed, 9 insertions(+), 6 deletions(-)


diff --git a/Objects/listobject.c b/Objects/listobject.c
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -634,14 +634,17 @@
     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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list