gh-106524: Fix a crash in _sre.template() (GH-106525)

Some items remained uninitialized if _sre.template() was called with invalid
indices. Then attempt to clear them in the destructor led to dereferencing
of uninitialized pointer.
This commit is contained in:
Radislav Chugunov 2023-07-08 10:47:01 +03:00 committed by GitHub
parent 1c9e493462
commit 2ef1dc37f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -2418,6 +2418,16 @@ class ReTests(unittest.TestCase):
p.terminate()
p.join()
def test_sre_template_invalid_group_index(self):
# see gh-106524
import _sre
with self.assertRaises(TypeError) as cm:
_sre.template("", ["", -1, ""])
self.assertIn("invalid template", str(cm.exception))
with self.assertRaises(TypeError) as cm:
_sre.template("", ["", (), ""])
self.assertIn("an integer is required", str(cm.exception))
def get_debug_out(pat):
with captured_stdout() as out: