From 44605aa93d31d6dff64dab96126942f94cf1dfe9 Mon Sep 17 00:00:00 2001 From: Sergey Muraviov Date: Tue, 25 Mar 2025 16:28:38 +0300 Subject: gh-131711: Preventing the use of a null pointer in set_tp_mro (#131713) --- Objects/typeobject.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fc4950e..4f44d59 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -574,14 +574,16 @@ _PyType_GetMRO(PyTypeObject *self) static inline void set_tp_mro(PyTypeObject *self, PyObject *mro, int initial) { - assert(PyTuple_CheckExact(mro)); - if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) { - // XXX tp_mro can probably be statically allocated for each - // static builtin type. - assert(initial); - assert(self->tp_mro == NULL); - /* Other checks are done via set_tp_bases. */ - _Py_SetImmortal(mro); + if (mro != NULL) { + assert(PyTuple_CheckExact(mro)); + if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) { + // XXX tp_mro can probably be statically allocated for each + // static builtin type. + assert(initial); + assert(self->tp_mro == NULL); + /* Other checks are done via set_tp_bases. */ + _Py_SetImmortal(mro); + } } self->tp_mro = mro; } -- cgit v0.12