bpo-42150: Avoid buffer overflow in the new parser (GH-22978)

(cherry picked from commit e68c67805e)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Miss Skeleton (bot) 2020-10-25 16:24:56 -07:00 committed by GitHub
parent 83c86cf54b
commit 0b290dd217
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Fix possible buffer overflow in the new parser when checking for
continuation lines. Patch by Pablo Galindo.

View file

@ -989,7 +989,8 @@ bad_single_statement(Parser *p)
/* Newlines are allowed if preceded by a line continuation character
or if they appear inside a string. */
if (!cur || *(cur - 1) == '\\' || newline_in_string(p, cur)) {
if (!cur || (cur != p->tok->buf && *(cur - 1) == '\\')
|| newline_in_string(p, cur)) {
return 0;
}
char c = *cur;