]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40880: Fix invalid read in newline_in_string in pegen.c (#20666)
authorPablo Galindo <Pablogsal@gmail.com>
Fri, 5 Jun 2020 23:52:27 +0000 (00:52 +0100)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2020 23:52:27 +0000 (00:52 +0100)
* bpo-40880: Fix invalid read in newline_in_string in pegen.c

* Update Parser/pegen/pegen.c

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* Add NEWS entry

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2020-06-06-00-23-19.bpo-40880.fjdzSh.rst [new file with mode: 0644]
Parser/pegen/pegen.c

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 (file)
index 0000000..ab42f5c
--- /dev/null
@@ -0,0 +1,2 @@
+Fix invalid memory read in the new parser when checking newlines in string
+literals. Patch by Pablo Galindo.
index c55ff7e45c0da0920f3377a228e69f71c47dc87b..afe75d7f862eed0838fd9acb99c4f941f9dd4f13 100644 (file)
@@ -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;
         }
     }