[3.10] gh-92112: Fix crash triggered by an evil custom mro() (GH-92113) (#92370)

(cherry picked from commit 85354ed78c)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
This commit is contained in:
Jelle Zijlstra 2022-05-06 21:01:23 -07:00 committed by GitHub
parent 17f3b5cbfa
commit 4674b315e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View file

@ -5737,6 +5737,23 @@ class MroTest(unittest.TestCase):
class A(metaclass=M):
pass
def test_disappearing_custom_mro(self):
"""
gh-92112: A custom mro() returning a result conflicting with
__bases__ and deleting itself caused a double free.
"""
class B:
pass
class M(DebugHelperMeta):
def mro(cls):
del M.mro
return (B,)
with self.assertRaises(TypeError):
class A(metaclass=M):
pass
if __name__ == "__main__":
unittest.main()