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 96c5932794)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-10-02 23:33:42 -07:00 committed by GitHub
parent 97f998a4df
commit 063755c201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Fix a possible null pointer dereference in bytesobject.c. Patch by Zackery
Spytz.

View File

@ -448,7 +448,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 *