[Python-checkins] bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580)
miss-islington
webhook-mailer at python.org
Wed Nov 17 18:43:49 EST 2021
https://github.com/python/cpython/commit/b455df59a8eca1b0c0793bc11a116ffc2829b175
commit: b455df59a8eca1b0c0793bc11a116ffc2829b175
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-11-17T15:43:14-08:00
summary:
bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580)
(cherry picked from commit df4ae55e66e34ea8de6a34f0b104871ddaf35d53)
Co-authored-by: Pablo Galindo Salgado <Pablogsal at gmail.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst
M Parser/pegen.c
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.c b/Parser/pegen.c
index 170d28b94d4ee..c6570eb1bd0b4 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -389,6 +389,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, 0, -1, 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;
Py_ssize_t end_col_offset = -1;
More information about the Python-checkins
mailing list