]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-113602: Bail out when the parser tries to override existing errors (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 2 Jan 2024 13:27:20 +0000 (14:27 +0100)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2024 13:27:20 +0000 (13:27 +0000)
gh-113602: Bail out when the parser tries to override existing errors (GH-113607)
(cherry picked from commit 9ed36d533ab8b256f0a589b5be6d7a2fdcf4aff2)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2024-01-01-00-07-02.gh-issue-113602.cWuTzk.rst [new file with mode: 0644]
Parser/pegen_errors.c

index fe3ea3d248b0ed969e094e5e706ce4cfb14bd583..d8f1ee5f8af86c3f07e6b20aaa39d4389bef801d 100644 (file)
@@ -2322,6 +2322,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 (file)
index 0000000..5e06465
--- /dev/null
@@ -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
index c13ba97a2480ca97578919918bf4c12eebf5118d..cefec5d27571bfc892624cb6c7130005c2d71d1f 100644 (file)
@@ -309,6 +309,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;