Skip to content

Commit 499f1d0

Browse files
[3.12] gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (#113652)
gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (cherry picked from commit 9ed36d5) Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent 20631e8 commit 499f1d0

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,8 @@ def test_error_parenthesis(self):
23222322
"""
23232323
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
23242324

2325+
self._check_error("match y:\n case e(e=v,v,", " was never closed")
2326+
23252327
# Examples with dencodings
23262328
s = b'# coding=latin\n(aaaaaaaaaaaaaaaaa\naaaaaaaaaaa\xb5'
23272329
self._check_error(s, r"'\(' was never closed")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an error that was causing the parser to try to overwrite existing errors
2+
and crashing in the process. Patch by Pablo Galindo

Parser/pegen_errors.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
309309
Py_ssize_t end_lineno, Py_ssize_t end_col_offset,
310310
const char *errmsg, va_list va)
311311
{
312+
// Bail out if we already have an error set.
313+
if (p->error_indicator && PyErr_Occurred()) {
314+
return NULL;
315+
}
312316
PyObject *value = NULL;
313317
PyObject *errstr = NULL;
314318
PyObject *error_line = NULL;

0 commit comments

Comments
 (0)