]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Tue, 16 Nov 2021 19:51:52 +0000 (19:51 +0000)
committerGitHub <noreply@github.com>
Tue, 16 Nov 2021 19:51:52 +0000 (19:51 +0000)
Misc/NEWS.d/next/Core and Builtins/2021-11-16-19-00-27.bpo-45820.2X6Psr.rst [new file with mode: 0644]
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 (file)
index 0000000..c2ec3d6
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a segfault when the parser fails without reading any input. Patch by
+Pablo Galindo
index 8a3f740c359c0ce56635a99dce07544f640900dc..2931a40560867c2e1c190c0461e06b06095914c4 100644 (file)
@@ -368,6 +368,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;