Skip to content

Commit efe41d1

Browse files
smuravdiegorusso
authored andcommitted
pythongh-131711: Preventing the use of a null pointer in set_tp_mro (python#131713)
1 parent 9c2ddac commit efe41d1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Objects/typeobject.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,16 @@ _PyType_GetMRO(PyTypeObject *self)
574574
static inline void
575575
set_tp_mro(PyTypeObject *self, PyObject *mro, int initial)
576576
{
577-
assert(PyTuple_CheckExact(mro));
578-
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
579-
// XXX tp_mro can probably be statically allocated for each
580-
// static builtin type.
581-
assert(initial);
582-
assert(self->tp_mro == NULL);
583-
/* Other checks are done via set_tp_bases. */
584-
_Py_SetImmortal(mro);
577+
if (mro != NULL) {
578+
assert(PyTuple_CheckExact(mro));
579+
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
580+
// XXX tp_mro can probably be statically allocated for each
581+
// static builtin type.
582+
assert(initial);
583+
assert(self->tp_mro == NULL);
584+
/* Other checks are done via set_tp_bases. */
585+
_Py_SetImmortal(mro);
586+
}
585587
}
586588
self->tp_mro = mro;
587589
}

0 commit comments

Comments
 (0)