[Python-checkins] closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)

Benjamin Peterson webhook-mailer at python.org
Wed Aug 15 02:27:32 EDT 2018


https://github.com/python/cpython/commit/7c4ab2afb17b99eb3f61f9c73cbd548b5e0ad2c0
commit: 7c4ab2afb17b99eb3f61f9c73cbd548b5e0ad2c0
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2018-08-14T23:27:26-07:00
summary:

closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)

Avoid undefined pointer arithmetic with NULL.

files:
A Misc/NEWS.d/next/Core and Builtins/2018-08-14-03-52-43.bpo-34400.AJD0bz.rst
M Parser/parsetok.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-14-03-52-43.bpo-34400.AJD0bz.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-14-03-52-43.bpo-34400.AJD0bz.rst
new file mode 100644
index 000000000000..768f5a26c1a6
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-14-03-52-43.bpo-34400.AJD0bz.rst	
@@ -0,0 +1 @@
+Fix undefined behavior in parsetok.c.  Patch by Zackery Spytz.
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 00d741d2217e..b9c9fe8fa8c2 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -225,7 +225,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
         }
         else
             started = 1;
-        len = b - a; /* XXX this may compute NULL - NULL */
+        len = (a != NULL && b != NULL) ? b - a : 0;
         str = (char *) PyObject_MALLOC(len + 1);
         if (str == NULL) {
             err_ret->error = E_NOMEM;



More information about the Python-checkins mailing list