Skip to content

Commit 0823ffb

Browse files
committed
properly handle malloc failure (closes python#24044)
Patch by Christian Heimes.
1 parent 893cce9 commit 0823ffb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.7?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #24044: Fix possible null pointer dereference in list.sort in out of
14+
memory conditions.
15+
1316
- Issue #23055: Fixed a buffer overflow in PyUnicode_FromFormatV. Analysis
1417
and fix by Guido Vranken.
1518

Objects/listobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,10 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
19241924
keys = &ms.temparray[saved_ob_size+1];
19251925
else {
19261926
keys = PyMem_MALLOC(sizeof(PyObject *) * saved_ob_size);
1927-
if (keys == NULL)
1928-
return NULL;
1927+
if (keys == NULL) {
1928+
PyErr_NoMemory();
1929+
goto keyfunc_fail;
1930+
}
19291931
}
19301932

19311933
for (i = 0; i < saved_ob_size ; i++) {

0 commit comments

Comments
 (0)