Skip to content

Commit 0e73ea2

Browse files
bpo-33989: Ensure that ms.key_compare is always initialized in list_sort_impl(). (GH-8710)
(cherry picked from commit ebc793d) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 92ac01b commit 0e73ea2

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible crash in :meth:`list.sort` when sorting objects with
2+
``ob_type->tp_richcompare == NULL``. Patch by Zackery Spytz.

Objects/listobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,9 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
22792279
else if ((ms.key_richcompare = key_type->tp_richcompare) != NULL) {
22802280
ms.key_compare = unsafe_object_compare;
22812281
}
2282+
else {
2283+
ms.key_compare = safe_object_compare;
2284+
}
22822285
}
22832286
else {
22842287
ms.key_compare = safe_object_compare;

0 commit comments

Comments
 (0)