mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
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.
This commit is contained in:
parent
529f42645d
commit
61fc23ca10
2 changed files with 5 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Guard against a NULL pointer dereference within bytearrayobject triggered by
|
||||||
|
the ``bytearray() + bytearray()`` operation.
|
|
@ -266,7 +266,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b)
|
||||||
|
|
||||||
result = (PyByteArrayObject *) \
|
result = (PyByteArrayObject *) \
|
||||||
PyByteArray_FromStringAndSize(NULL, va.len + vb.len);
|
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.buf, va.len);
|
||||||
memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
|
memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue