Skip to content

Commit 063755c

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 <[email protected]>
1 parent 97f998a commit 063755c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
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
@@ -448,7 +448,7 @@ formatfloat(PyObject *v, int flags, int prec, int type,
448448
result = PyBytes_FromStringAndSize(p, len);
449449
PyMem_Free(p);
450450
*p_result = result;
451-
return str;
451+
return result != NULL ? str : NULL;
452452
}
453453

454454
static PyObject *

0 commit comments

Comments
 (0)