]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33989: Ensure that ms.key_compare is always initialized in list_sort_impl()....
authorZackery Spytz <zspytz@gmail.com>
Thu, 21 Feb 2019 07:47:14 +0000 (00:47 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 21 Feb 2019 07:47:14 +0000 (09:47 +0200)
Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst [new file with mode: 0644]
Objects/listobject.c

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 (file)
index 0000000..056a71c
--- /dev/null
@@ -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.
index a08b3b50dd9add9fb2ad8b6b39d4dae289d15355..cbd6e81ea472e6381f930b57c40f9dfc4e584d8b 100644 (file)
@@ -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;