bpo-33989: Ensure that ms.key_compare is always initialized in list_sort_impl(). (GH-8710)

(cherry picked from commit ebc793d6ac)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2019-02-21 00:05:22 -08:00 committed by GitHub
parent 92ac01b104
commit 0e73ea26a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View file

@ -0,0 +1,2 @@
Fix a possible crash in :meth:`list.sort` when sorting objects with
``ob_type->tp_richcompare == NULL``. Patch by Zackery Spytz.

View file

@ -2279,6 +2279,9 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
else if ((ms.key_richcompare = key_type->tp_richcompare) != NULL) {
ms.key_compare = unsafe_object_compare;
}
else {
ms.key_compare = safe_object_compare;
}
}
else {
ms.key_compare = safe_object_compare;