From 1c381ec4edfa6364474fa795a93ed1cccb6df903 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:22:39 +0100 Subject: [3.11] gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (#113653) gh-113602: Bail out when the parser tries to override existing errors (GH-113607) (cherry picked from commit 9ed36d533ab8b256f0a589b5be6d7a2fdcf4aff2) Signed-off-by: Pablo Galindo Co-authored-by: Pablo Galindo Salgado --- Lib/test/test_syntax.py | 2 ++ .../Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst | 2 ++ Parser/pegen_errors.c | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 050d084..9dd0f74 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -2143,6 +2143,8 @@ func( """ self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['") + self._check_error("match y:\n case e(e=v,v,", " was never closed") + # Examples with dencodings s = b'# coding=latin\n(aaaaaaaaaaaaaaaaa\naaaaaaaaaaa\xb5' self._check_error(s, r"'\(' was never closed") diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst b/Misc/NEWS.d/next/Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst new file mode 100644 index 0000000..5e06465 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst @@ -0,0 +1,2 @@ +Fix an error that was causing the parser to try to overwrite existing errors +and crashing in the process. Patch by Pablo Galindo diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c index fb9fa29..ccb0d37 100644 --- a/Parser/pegen_errors.c +++ b/Parser/pegen_errors.c @@ -299,6 +299,10 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, Py_ssize_t end_lineno, Py_ssize_t end_col_offset, const char *errmsg, va_list va) { + // Bail out if we already have an error set. + if (p->error_indicator && PyErr_Occurred()) { + return NULL; + } PyObject *value = NULL; PyObject *errstr = NULL; PyObject *error_line = NULL; -- cgit v0.12