From 0823ffb2fb16aa29cefd4c1b91edd82d9814e46a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 23 Apr 2015 17:04:36 -0400 Subject: properly handle malloc failure (closes #24044) Patch by Christian Heimes. --- Misc/NEWS | 3 +++ Objects/listobject.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index b54f267..895ff67 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 b9ef0d0..3642b39 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++) { -- cgit v0.12