summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-11-18 00:24:43 (GMT)
committerGitHub <noreply@github.com>2021-11-18 00:24:43 (GMT)
commit00ee14e814d35587ac55f89c7de871a01360c876 (patch)
tree9166e3239b6052200cc868ddb7b8266ef9ba05a0 /Parser
parent0ef308a2890571c850c624fb99ac00f8951363c6 (diff)
downloadcpython-00ee14e814d35587ac55f89c7de871a01360c876.zip
cpython-00ee14e814d35587ac55f89c7de871a01360c876.tar.gz
cpython-00ee14e814d35587ac55f89c7de871a01360c876.tar.bz2
[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@gmail.com> Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen/pegen.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index 2e986c5..cdfbc12 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) {