Mailing List Archive

bpo-44143: Fix crash in the parser when raising tokenizer errors with an exception set (GH-26144) (GH-26148)
https://github.com/python/cpython/commit/1afaaf5a2dc901377bb17f6fbe0cff7bf3b797e3
commit: 1afaaf5a2dc901377bb17f6fbe0cff7bf3b797e3
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: pablogsal <Pablogsal@gmail.com>
date: 2021-05-15T18:39:18+01:00
summary:

bpo-44143: Fix crash in the parser when raising tokenizer errors with an exception set (GH-26144) (GH-26148)

(cherry picked from commit 80b089179fa798c8ceaab2ff699c82499b2fcacd)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2021-05-15-17-30-57.bpo-44143.7UTS6H.rst
M Lib/test/test_exceptions.py
M Parser/pegen.c

diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 1fe479fbe83092..aefdd7b769f289 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -242,6 +242,7 @@ def baz():
""", 9, 24)
check("pass\npass\npass\n(1+)\npass\npass\npass", 4, 4)
check("(1+)", 1, 4)
+ check("[interesting\nfoo()\n", 1, 1)

# Errors thrown by symtable.c
check('x = [(yield i) for i in range(3)]', 1, 5)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-05-15-17-30-57.bpo-44143.7UTS6H.rst b/Misc/NEWS.d/next/Core and Builtins/2021-05-15-17-30-57.bpo-44143.7UTS6H.rst
new file mode 100644
index 00000000000000..a4e88e55723e4d
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-05-15-17-30-57.bpo-44143.7UTS6H.rst
@@ -0,0 +1,2 @@
+Fixed a crash in the parser that manifest when raising tokenizer errors when
+an existing exception was present. Patch by Pablo Galindo.
diff --git a/Parser/pegen.c b/Parser/pegen.c
index 6080cec1489ed8..c2f25402ca4e13 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1259,6 +1259,7 @@ _PyPegen_check_tokenizer_errors(Parser *p) {
if (p->tok->level != 0) {
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
if (current_err_line > error_lineno) {
+ PyErr_Clear();
raise_unclosed_parentheses_error(p);
return -1;
}

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins