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:
parent
3d1c06e8b9
commit
33672c0191
|
@ -0,0 +1,2 @@
|
|||
Guard against a NULL pointer dereference within bytearrayobject triggered by
|
||||
the ``bytearray() + bytearray()`` operation.
|
|
@ -276,7 +276,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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue