Skip to content

Commit

Permalink
bpo-41175: Guard against a NULL pointer dereference within bytearrayo…
Browse files Browse the repository at this point in the history
…bject (pythonGH-21240)

The issue is triggered by the bytearray() + bytearray() operation.

Detected by GCC 10 static analysis tool.
  • Loading branch information
stratakis committed Jul 8, 2020
1 parent 529f426 commit 61fc23c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
@@ -0,0 +1,2 @@
Guard against a NULL pointer dereference within bytearrayobject triggered by
the ``bytearray() + bytearray()`` operation.
4 changes: 3 additions & 1 deletion Objects/bytearrayobject.c
Expand Up @@ -266,7 +266,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b)

result = (PyByteArrayObject *) \
PyByteArray_FromStringAndSize(NULL, va.len + vb.len);
if (result != NULL) {
// result->ob_bytes is NULL if result is an empty string:
// if va.len + vb.len equals zero.
if (result != NULL && result->ob_bytes != NULL) {
memcpy(result->ob_bytes, va.buf, va.len);
memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
}
Expand Down

0 comments on commit 61fc23c

Please sign in to comment.