bpo-40880: Fix invalid read in newline_in_string in pegen.c (#20666)

* bpo-40880: Fix invalid read in newline_in_string in pegen.c

* Update Parser/pegen/pegen.c

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>

* Add NEWS entry

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
Pablo Galindo 2020-06-06 00:52:27 +01:00 committed by GitHub
parent a54096e305
commit 2e6593db00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Fix invalid memory read in the new parser when checking newlines in string
literals. Patch by Pablo Galindo.

View File

@ -937,8 +937,8 @@ _PyPegen_number_token(Parser *p)
static int // bool
newline_in_string(Parser *p, const char *cur)
{
for (char c = *cur; cur >= p->tok->buf; c = *--cur) {
if (c == '\'' || c == '"') {
for (const char *c = cur; c >= p->tok->buf; c--) {
if (*c == '\'' || *c == '"') {
return 1;
}
}