summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-08 08:12:33 (GMT)
committerGitHub <noreply@github.com>2023-07-08 08:12:33 (GMT)
commit8fdb0587935b66c3942c1740ab5e387b2ea415bb (patch)
tree0dc658182f74225d130ad393eb4d29d357b141f1 /Lib/test
parent2ade2fc148fb25a0306d5b14f705396d98c8b926 (diff)
downloadcpython-8fdb0587935b66c3942c1740ab5e387b2ea415bb.zip
cpython-8fdb0587935b66c3942c1740ab5e387b2ea415bb.tar.gz
cpython-8fdb0587935b66c3942c1740ab5e387b2ea415bb.tar.bz2
[3.12] gh-106524: Fix a crash in _sre.template() (GH-106525) (GH-106544)
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. (cherry picked from commit 2ef1dc37f02b08536b677dd23ec51541a60effd7) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
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 11628a2..a05a1c9 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2441,6 +2441,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: