]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131711: Preventing the use of a null pointer in set_tp_mro (#131713)
authorSergey Muraviov <smurav@mail.ru>
Tue, 25 Mar 2025 13:28:38 +0000 (16:28 +0300)
committerGitHub <noreply@github.com>
Tue, 25 Mar 2025 13:28:38 +0000 (14:28 +0100)
Objects/typeobject.c

index fc4950ef30aec64bb1ba5ea930bb34a8d1e63646..4f44d590fb49aa594d7a0d38f989c1b423fe1925 100644 (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;
 }