Skip to content

Conversation

smurav
Copy link
Contributor

@smurav smurav commented Mar 25, 2025

In some cases, a null pointer may be used in function set_tp_mro.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner
Copy link
Member

I can reproduce a crash using this local change:

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index fc4950ef30a..6e880c5235a 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1658,7 +1658,11 @@ mro_hierarchy(PyTypeObject *type, PyObject *temp)
         tuple = PyTuple_Pack(3, type, new_mro, old_mro);
     }
     else {
+#if 0
         tuple = PyTuple_Pack(2, type, new_mro);
+#else
+        tuple = NULL;
+#endif
     }
 
     if (tuple != NULL) {

if I run the test:

$ ./python -m test -v test_descr -m test_incomplete_set_bases_on_self
(...)
test_incomplete_set_bases_on_self (test.test_descr.MroTest.test_incomplete_set_bases_on_self)
type_set_bases must be aware that type->tp_mro can be NULL. ... Fatal Python error: Segmentation fault

Current thread 0x00007f549a70d740 (most recent call first):
  File "/home/vstinner/python/main/Lib/test/test_descr.py", line 5778 in mro
  File "/home/vstinner/python/main/Lib/test/test_descr.py", line 5748 in __new__
  File "/home/vstinner/python/main/Lib/test/test_descr.py", line 5782 in test_incomplete_set_bases_on_self
(...)

@vstinner vstinner merged commit 44605aa into python:main Mar 25, 2025
49 checks passed
@vstinner
Copy link
Member

Merged, thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants