]> granicus.if.org Git - python/commitdiff
closes bpo-34400: Fix undefined behavior in parsetok(). (GH-4439)
authorZackery Spytz <zspytz@gmail.com>
Wed, 15 Aug 2018 06:27:26 +0000 (00:27 -0600)
committerBenjamin Peterson <benjamin@python.org>
Wed, 15 Aug 2018 06:27:26 +0000 (23:27 -0700)
Avoid undefined pointer arithmetic with NULL.

Misc/NEWS.d/next/Core and Builtins/2018-08-14-03-52-43.bpo-34400.AJD0bz.rst [new file with mode: 0644]
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 (file)
index 0000000..768f5a2
--- /dev/null
@@ -0,0 +1 @@
+Fix undefined behavior in parsetok.c.  Patch by Zackery Spytz.
index 00d741d2217e8f679dabcf9ff746e4a0016957f5..b9c9fe8fa8c29e71626c8d56783c02faa236cf25 100644 (file)
@@ -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;