From ebc793d6acb9650b9f497808e059805892031d74 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Thu, 21 Feb 2019 00:47:14 -0700 Subject: bpo-33989: Ensure that ms.key_compare is always initialized in list_sort_impl(). (GH-8710) --- .../next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst | 2 ++ Objects/listobject.c | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst new file mode 100644 index 0000000..056a71c --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst @@ -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. diff --git a/Objects/listobject.c b/Objects/listobject.c index a08b3b5..cbd6e81 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2334,6 +2334,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; -- cgit v0.12