[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>
This commit is contained in:
Miss Islington (bot) 2021-11-17 16:24:43 -08:00 committed by GitHub
parent 0ef308a289
commit 00ee14e814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

2
.gitignore vendored
View file

@ -136,5 +136,7 @@ Tools/ssl/win32
!/Python/
# Artifacts generated by 3.11 lying around when switching branches:
/_bootstrap_python
/Programs/_freeze_module
/Python/deepfreeze/
/Python/frozen_modules/

View file

@ -0,0 +1,2 @@
Fix a segfault when the parser fails without reading any input. Patch by
Pablo Galindo

View file

@ -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) {