From c90c4bffe77564cfec97edd817eee6c8b1379fc1 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 6 Jun 2020 00:14:16 +0100 Subject: [PATCH 1/3] bpo-40880: Fix invalid read in newline_in_string in pegen.c --- Parser/pegen/pegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index c55ff7e45c0da0..fcd5303877389f 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -937,7 +937,7 @@ _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) { + for (char c = *cur; cur > p->tok->buf; c = *--cur) { if (c == '\'' || c == '"') { return 1; } From 8fda8b133d28759c6b3881b5a519df899d449d14 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 6 Jun 2020 00:21:56 +0100 Subject: [PATCH 2/3] Update Parser/pegen/pegen.c Co-authored-by: Lysandros Nikolaou --- Parser/pegen/pegen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index fcd5303877389f..afe75d7f862eed 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -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; } } From 7eead1ddb26c88cfb2ad0670a1d2257eaec5b9ff Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 6 Jun 2020 00:23:59 +0100 Subject: [PATCH 3/3] Add NEWS entry --- .../Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst new file mode 100644 index 00000000000000..ab42f5c205f81b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst @@ -0,0 +1,2 @@ +Fix invalid memory read in the new parser when checking newlines in string +literals. Patch by Pablo Galindo.