gh-131711: Preventing the use of a null pointer in set_tp_mro (#131713)

This commit is contained in:
Sergey Muraviov 2025-03-25 16:28:38 +03:00 committed by GitHub
parent f1967e7249
commit 44605aa93d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}