Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61fc23c

Browse files
authored
bpo-41175: Guard against a NULL pointer dereference within bytearrayobject (GH-21240)
The issue is triggered by the bytearray() + bytearray() operation. Detected by GCC 10 static analysis tool.
1 parent 529f426 commit 61fc23c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Guard against a NULL pointer dereference within bytearrayobject triggered by
2+
the ``bytearray() + bytearray()`` operation.

Objects/bytearrayobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b)
266266

267267
result = (PyByteArrayObject *) \
268268
PyByteArray_FromStringAndSize(NULL, va.len + vb.len);
269-
if (result != NULL) {
269+
// result->ob_bytes is NULL if result is an empty string:
270+
// if va.len + vb.len equals zero.
271+
if (result != NULL && result->ob_bytes != NULL) {
270272
memcpy(result->ob_bytes, va.buf, va.len);
271273
memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
272274
}

0 commit comments

Comments
 (0)