]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44143: Fix crash in the parser when raising tokenizer errors with an exception...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 15 May 2021 17:39:18 +0000 (10:39 -0700)
committerGitHub <noreply@github.com>
Sat, 15 May 2021 17:39:18 +0000 (18:39 +0100)
(cherry picked from commit 80b089179fa798c8ceaab2ff699c82499b2fcacd)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Lib/test/test_exceptions.py
Misc/NEWS.d/next/Core and Builtins/2021-05-15-17-30-57.bpo-44143.7UTS6H.rst [new file with mode: 0644]
Parser/pegen.c

index 1fe479fbe83092f9100cf65ff06ec346be102459..aefdd7b769f289f76c3e4b2b1be2c6a707d0ec64 100644 (file)
@@ -242,6 +242,7 @@ class ExceptionTests(unittest.TestCase):
             """, 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 (file)
index 0000000..a4e88e5
--- /dev/null
@@ -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.
index 6080cec1489ed802a25c28f1571d4163f29b8184..c2f25402ca4e13bc622c6fb2a071b2fede97d734 100644 (file)
@@ -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;
                     }