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

Miss Islington (bot) webhook-mailer at python.org
Thu Feb 21 03:05:27 EST 2019


https://github.com/python/cpython/commit/0e73ea26a55abc0ce2ee1153e5509bcaef4736cf
commit: 0e73ea26a55abc0ce2ee1153e5509bcaef4736cf
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-02-21T00:05:22-08:00
summary:

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

(cherry picked from commit ebc793d6acb9650b9f497808e059805892031d74)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2018-08-08-20-52-55.bpo-33989.TkLBui.rst
M 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
index 000000000000..056a71c480ad
--- /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 de73b8bf80fd..7dc68a73bdb6 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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;



More information about the Python-checkins mailing list