From 6580e52b64cb207f03a1bf86a18f088b081c10f4 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 2 Oct 2018 23:34:05 -0700 Subject: bpo-34879: Fix a possible null pointer dereference in bytesobject.c (GH-9683) 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 --- .../next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst | 2 ++ Objects/bytesobject.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst 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 index 0000000..5775a21 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-10-02-22-55-11.bpo-34879.7VNH2a.rst @@ -0,0 +1,2 @@ +Fix a possible null pointer dereference in bytesobject.c. Patch by Zackery +Spytz. diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 26e59d1..04ebe0b 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -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 * -- cgit v0.12