From: Benjamin Peterson Date: Thu, 23 Apr 2015 21:04:36 +0000 (-0400) Subject: properly handle malloc failure (closes #24044) X-Git-Tag: 3.2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0823ffb2fb16aa29cefd4c1b91edd82d9814e46a;p=thirdparty%2FPython%2Fcpython.git properly handle malloc failure (closes #24044) Patch by Christian Heimes. --- diff --git a/Misc/NEWS b/Misc/NEWS index b54f26708327..895ff67403f4 100644 --- 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. diff --git a/Objects/listobject.c b/Objects/listobject.c index b9ef0d0287f4..3642b39dd132 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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++) {