From 15fec5627ac343afd0bfa1e847746071982d5172 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 5 Jun 2020 17:13:14 -0700 Subject: bpo-40880: Fix invalid read in newline_in_string in pegen.c (GH-20666) * bpo-40880: Fix invalid read in newline_in_string in pegen.c * Update Parser/pegen/pegen.c Co-authored-by: Lysandros Nikolaou * Add NEWS entry Co-authored-by: Lysandros Nikolaou (cherry picked from commit 2e6593db0086004a1ca7f7049218ff9573d473c2) Co-authored-by: Pablo Galindo --- .../next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst | 2 ++ Parser/pegen/pegen.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 0000000..ab42f5c --- /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. diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 6608fd8..76442de 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -936,8 +936,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; } } -- cgit v0.12