[Python-checkins] [3.9] bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580) (GH-29584)

ambv webhook-mailer at python.org
Wed Nov 17 19:25:05 EST 2021


https://github.com/python/cpython/commit/00ee14e814d35587ac55f89c7de871a01360c876
commit: 00ee14e814d35587ac55f89c7de871a01360c876
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-11-18T01:24:43+01:00
summary:

[3.9] bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580) (GH-29584)

Co-authored-by: Pablo Galindo Salgado <Pablogsal at gmail.com>
Co-authored-by: Łukasz Langa <lukasz at langa.pl>

files:
A Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst
M .gitignore
M Parser/pegen/pegen.c

diff --git a/.gitignore b/.gitignore
index 864152451dd9d..0dd3aee5c3151 100644
--- a/.gitignore
+++ b/.gitignore
@@ -136,5 +136,7 @@ Tools/ssl/win32
 !/Python/
 
 # Artifacts generated by 3.11 lying around when switching branches:
+/_bootstrap_python
 /Programs/_freeze_module
+/Python/deepfreeze/
 /Python/frozen_modules/ 
\ No newline at end of file
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst
new file mode 100644
index 0000000000000..c2ec3d690cd4b
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst	
@@ -0,0 +1,2 @@
+Fix a segfault when the parser fails without reading any input. Patch by
+Pablo Galindo
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index 2e986c5294f19..cdfbc12d16a34 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -364,6 +364,14 @@ tokenizer_error(Parser *p)
 void *
 _PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
 {
+    if (p->fill == 0) {
+        va_list va;
+        va_start(va, errmsg);
+        _PyPegen_raise_error_known_location(p, errtype, 0, 0, errmsg, va);
+        va_end(va);
+        return NULL;
+    }
+
     Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
     Py_ssize_t col_offset;
     if (t->col_offset == -1) {



More information about the Python-checkins mailing list