]> granicus.if.org Git - python/commitdiff
properly handle malloc failure (closes #24044)
authorBenjamin Peterson <benjamin@python.org>
Thu, 23 Apr 2015 21:04:36 +0000 (17:04 -0400)
committerBenjamin Peterson <benjamin@python.org>
Thu, 23 Apr 2015 21:04:36 +0000 (17:04 -0400)
Patch by Christian Heimes.

Misc/NEWS
Objects/listobject.c

index b54f267083275f5bc4c0dcc77973d88c427876a8..895ff67403f495c25fa963e7abbde792f3bd8c18 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.7?
 Core and Builtins
 -----------------
 
+- Issue #24044: Fix possible null pointer dereference in list.sort in out of
+  memory conditions.
+
 - Issue #23055: Fixed a buffer overflow in PyUnicode_FromFormatV.  Analysis
   and fix by Guido Vranken.
 
index b9ef0d0287f42b645d6df831226441d16880fab6..3642b39dd132f6402f0ffe30c0e91bd01f8540ec 100644 (file)
@@ -1924,8 +1924,10 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
             keys = &ms.temparray[saved_ob_size+1];
         else {
             keys = PyMem_MALLOC(sizeof(PyObject *) * saved_ob_size);
-            if (keys == NULL)
-                return NULL;
+            if (keys == NULL) {
+                PyErr_NoMemory();
+                goto keyfunc_fail;
+            }
         }
 
         for (i = 0; i < saved_ob_size ; i++) {