From f5452aff708ae9010a4d4efaa36307c61402fda1 Mon Sep 17 00:00:00 2001 From: MonocleAI <54963236+monocle-ai@users.noreply.github.com> Date: Wed, 14 Oct 2020 06:58:26 -0700 Subject: [PATCH 1/3] Fixed unchecked return in Objects/typeobject.c Unchecked return in Objects/typeobject.c and possible uninitialized variables in cls and new_mro --- Objects/typeobject.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3bb2c338fe0b530..d0bbe40722824a1 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -823,8 +823,10 @@ type_set_bases(PyTypeObject *type, PyObject *new_bases, void *context) PyTypeObject *cls; PyObject *new_mro, *old_mro = NULL; - PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), - "", 2, 3, &cls, &new_mro, &old_mro); + if(!PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), + "", 2, 3, &cls, &new_mro, &old_mro)) { + return NULL; + } /* Do not rollback if cls has a newer version of MRO. */ if (cls->tp_mro == new_mro) { Py_XINCREF(old_mro); From 0a13d68e339efc2265211b634a2e0856d11838f8 Mon Sep 17 00:00:00 2001 From: MonocleAI <54963236+monocle-ai@users.noreply.github.com> Date: Thu, 15 Oct 2020 06:22:35 -0700 Subject: [PATCH 2/3] Update typeobject.c Removed return to call cleanup on temp in all the cases --- Objects/typeobject.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d0bbe40722824a1..dab57147cf28956 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -823,16 +823,15 @@ type_set_bases(PyTypeObject *type, PyObject *new_bases, void *context) PyTypeObject *cls; PyObject *new_mro, *old_mro = NULL; - if(!PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), + if(PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), "", 2, 3, &cls, &new_mro, &old_mro)) { - return NULL; - } - /* Do not rollback if cls has a newer version of MRO. */ - if (cls->tp_mro == new_mro) { - Py_XINCREF(old_mro); - cls->tp_mro = old_mro; - Py_DECREF(new_mro); - } + /* Do not rollback if cls has a newer version of MRO. */ + if (cls->tp_mro == new_mro) { + Py_XINCREF(old_mro); + cls->tp_mro = old_mro; + Py_DECREF(new_mro); + } + } } Py_DECREF(temp); From a196e6a12f923ebd2fefe0f3950c7205a2f3c0f3 Mon Sep 17 00:00:00 2001 From: MonocleAI <54963236+monocle-ai@users.noreply.github.com> Date: Thu, 15 Oct 2020 06:29:16 -0700 Subject: [PATCH 3/3] Create 2020-10-15-06-28-50.bpo-42034.MonocleAI.rst --- .../next/Library/2020-10-15-06-28-50.bpo-42034.MonocleAI.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-10-15-06-28-50.bpo-42034.MonocleAI.rst diff --git a/Misc/NEWS.d/next/Library/2020-10-15-06-28-50.bpo-42034.MonocleAI.rst b/Misc/NEWS.d/next/Library/2020-10-15-06-28-50.bpo-42034.MonocleAI.rst new file mode 100644 index 000000000000000..f78f1b2b1a5a140 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-10-15-06-28-50.bpo-42034.MonocleAI.rst @@ -0,0 +1 @@ +Fix unchecked return in Objects/typeobject.c. The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in undefined behavior.