Skip to content

Commit b455df5

Browse files
bpo-45820: Fix a segfault when the parser fails without reading any input (GH-29580)
(cherry picked from commit df4ae55) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent e3aa9fd commit b455df5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
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.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ tokenizer_error(Parser *p)
389389
void *
390390
_PyPegen_raise_error(Parser *p, PyObject *errtype, const char *errmsg, ...)
391391
{
392+
if (p->fill == 0) {
393+
va_list va;
394+
va_start(va, errmsg);
395+
_PyPegen_raise_error_known_location(p, errtype, 0, 0, 0, -1, errmsg, va);
396+
va_end(va);
397+
return NULL;
398+
}
399+
392400
Token *t = p->known_err_token != NULL ? p->known_err_token : p->tokens[p->fill - 1];
393401
Py_ssize_t col_offset;
394402
Py_ssize_t end_col_offset = -1;

0 commit comments

Comments
 (0)