Skip to content

Commit 6580e52

Browse files
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 96c5932) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent f1e8be7 commit 6580e52

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible null pointer dereference in bytesobject.c. Patch by Zackery
2+
Spytz.

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ formatfloat(PyObject *v, int flags, int prec, int type,
446446
result = PyBytes_FromStringAndSize(p, len);
447447
PyMem_Free(p);
448448
*p_result = result;
449-
return str;
449+
return result != NULL ? str : NULL;
450450
}
451451

452452
static PyObject *

0 commit comments

Comments
 (0)