https://github.com/python/cpython/commit/44605aa93d31d6dff64dab96126942f94cf1dfe9
commit: 44605aa93d31d6dff64dab96126942f94cf1dfe9
branch: main
author: Sergey Muraviov <[email protected]>
committer: vstinner <[email protected]>
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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]