https://github.com/python/cpython/commit/44605aa93d31d6dff64dab96126942f94cf1dfe9 commit: 44605aa93d31d6dff64dab96126942f94cf1dfe9 branch: main author: Sergey Muraviov <smu...@mail.ru> committer: vstinner <vstin...@python.org> date: 2025-03-25T14:28:38+01:00 summary:
gh-131711: Preventing the use of a null pointer in set_tp_mro (#131713) files: M Objects/typeobject.c diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fc4950ef30aec6..4f44d590fb49aa 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; } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com