diff options
author | Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> | 2023-07-08 10:47:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-08 10:47:01 +0300 |
commit | 2ef1dc37f02b08536b677dd23ec51541a60effd7 (patch) | |
tree | e86725b69ca4d321cb5ccc1397df5ca29a5195fc /Lib/test | |
parent | 1c9e4934621627fbbfeada8d9dd87ecba4e446b0 (diff) | |
download | cpython-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.py | 10 |
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: |