From 2ef1dc37f02b08536b677dd23ec51541a60effd7 Mon Sep 17 00:00:00 2001 From: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Date: Sat, 8 Jul 2023 10:47:01 +0300 Subject: 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. --- Lib/test/test_re.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Lib/test') diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index e4d14356402..8f26d0aacf4 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -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: -- cgit v1.2.3