Check that data_ is non-null before memcpy in EnsureCapacityWithHeadroom
Since we've passed IsConsistent(), if data_ is null, size_ must be zero, so we might attempt to copy zero bytes from a nullptr. This does not seem to cause problems in practice, but is still undefined behaviour. This was caught on an UBsan test run in Firefox. Bug: webrtc:11613 Change-Id: Iad795bf19ed69b56e066958a54a7e3a434b996cf Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176280 Commit-Queue: Dan Minor <dminor@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31386}
This commit is contained in:
@ -370,7 +370,9 @@ class BufferT {
|
||||
: capacity;
|
||||
|
||||
std::unique_ptr<T[]> new_data(new T[new_capacity]);
|
||||
std::memcpy(new_data.get(), data_.get(), size_ * sizeof(T));
|
||||
if (data_ != nullptr) {
|
||||
std::memcpy(new_data.get(), data_.get(), size_ * sizeof(T));
|
||||
}
|
||||
MaybeZeroCompleteBuffer();
|
||||
data_ = std::move(new_data);
|
||||
capacity_ = new_capacity;
|
||||
|
Reference in New Issue
Block a user