gh-113602: Bail out when the parser tries to override existing errors (#113607)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
Pablo Galindo Salgado 2024-01-02 13:00:52 +00:00 committed by GitHub
parent 8ff44f8554
commit 9ed36d533a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -2360,6 +2360,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")

View File

@ -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

View File

@ -311,6 +311,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;