Skip to content

Commit 00ee14e

Browse files
miss-islingtonpablogsalambv
authored
[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 <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 0ef308a commit 00ee14e

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,7 @@ Tools/ssl/win32
136136
!/Python/
137137

138138
# Artifacts generated by 3.11 lying around when switching branches:
139+
/_bootstrap_python
139140
/Programs/_freeze_module
141+
/Python/deepfreeze/
140142
/Python/frozen_modules/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a segfault when the parser fails without reading any input. Patch by
2+
Pablo Galindo

Parser/pegen/pegen.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ tokenizer_error(Parser *p)
364364
void *
365365
_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
366366
{
367+
if (p->fill == 0) {
368+
va_list va;
369+
va_start(va, errmsg);
370+
_PyPegen_raise_error_known_location(p, errtype, 0, 0, errmsg, va);
371+
va_end(va);
372+
return NULL;
373+
}
374+
367375
Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
368376
Py_ssize_t col_offset;
369377
if (t->col_offset == -1) {

0 commit comments

Comments
 (0)