gh-103656: Transfer f-string buffers to parser to avoid use-after-free (GH-103896)

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
Lysandros Nikolaou 2023-04-26 19:33:31 -06:00 committed by GitHub
parent 76632b836c
commit 9169a56fad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 146 additions and 66 deletions

View file

@ -165,6 +165,7 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
int ret = 0;
struct token new_token;
new_token.metadata = NULL;
for (;;) {
switch (_PyTokenizer_Get(p->tok, &new_token)) {
@ -192,6 +193,7 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
exit:
Py_XDECREF(new_token.metadata);
// If we're in an f-string, we want the syntax error in the expression part
// to propagate, so that tokenizer errors (like expecting '}') that happen afterwards
// do not swallow it.