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 00000000000000..f78f1b2b1a5a14 --- /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. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3bb2c338fe0b53..dab57147cf2895 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -823,14 +823,15 @@ 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); - /* 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); - } + if(PyArg_UnpackTuple(PyList_GET_ITEM(temp, i), + "", 2, 3, &cls, &new_mro, &old_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);