]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34879: Fix a possible null pointer dereference in bytesobject.c (GH-9683)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 3 Oct 2018 06:34:05 +0000 (23:34 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Oct 2018 06:34:05 +0000 (23:34 -0700)
formatfloat() was not checking if PyBytes_FromStringAndSize()
failed, which could lead to a null pointer dereference in
_PyBytes_FormatEx().
(cherry picked from commit 96c593279400693226d5a560c420ae0fcf1731b9)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst [new file with mode: 0644]
Objects/bytesobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst b/Misc/NEWS.d/next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst
new file mode 100644 (file)
index 0000000..5775a21
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a possible null pointer dereference in bytesobject.c.  Patch by Zackery
+Spytz.
index 26e59d1073c14f6c385ea88bddbdce3f43971b5b..04ebe0b701e6e3b20a27b5323b90d6c798d921b2 100644 (file)
@@ -446,7 +446,7 @@ formatfloat(PyObject *v, int flags, int prec, int type,
     result = PyBytes_FromStringAndSize(p, len);
     PyMem_Free(p);
     *p_result = result;
-    return str;
+    return result != NULL ? str : NULL;
 }
 
 static PyObject *