Skip to content

Commit 0b290dd

Browse files
bpo-42150: Avoid buffer overflow in the new parser (GH-22978)
(cherry picked from commit e68c678) Co-authored-by: Pablo Galindo <[email protected]>
1 parent 83c86cf commit 0b290dd

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible buffer overflow in the new parser when checking for
2+
continuation lines. Patch by Pablo Galindo.

Parser/pegen/pegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,8 @@ bad_single_statement(Parser *p)
989989

990990
/* Newlines are allowed if preceded by a line continuation character
991991
or if they appear inside a string. */
992-
if (!cur || *(cur - 1) == '\\' || newline_in_string(p, cur)) {
992+
if (!cur || (cur != p->tok->buf && *(cur - 1) == '\\')
993+
|| newline_in_string(p, cur)) {
993994
return 0;
994995
}
995996
char c = *cur;

0 commit comments

Comments
 (0)