bpo-42150: Avoid buffer overflow in the new parser (GH-22978)
(cherry picked from commit e68c67805e6a4c4ec80bea64be0e8373cc02d322)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index 2c435fb..a7643fc 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -989,7 +989,8 @@
/* 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;