aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test
diff options
context:
space:
mode:
authorRadislav Chugunov <52372310+chgnrdv@users.noreply.github.com>2023-07-08 10:47:01 +0300
committerGitHub <noreply@github.com>2023-07-08 10:47:01 +0300
commit2ef1dc37f02b08536b677dd23ec51541a60effd7 (patch)
treee86725b69ca4d321cb5ccc1397df5ca29a5195fc /Lib/test
parent1c9e4934621627fbbfeada8d9dd87ecba4e446b0 (diff)
downloadcpython-2ef1dc37f02b08536b677dd23ec51541a60effd7.tar.gz
cpython-2ef1dc37f02b08536b677dd23ec51541a60effd7.zip
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_re.py10
1 files changed, 10 insertions, 0 deletions
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: