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.
(cherry picked from commit 61fc23ca10)

Co-authored-by: stratakis <cstratak@redhat.com>
This commit is contained in:
Miss Islington (bot) 2020-07-10 03:18:45 -07:00 committed by GitHub
parent fd27fb7f3d
commit 51b36ed96d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -273,7 +273,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);
}