Prevent UB on BufferT::AppendData.
As per https://en.cppreference.com/w/cpp/string/byte/memcpy, calling std::memcpy with dest or src as nullptr is UB. This CL prevents this from happening and is also looking into why UBSan didn't catch the issue. Bug: webrtc:14292 Change-Id: I99833f28ac865719d0dcb02c4de00f33a48c3992 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271502 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37783}
This commit is contained in:
parent
2f764dd53d
commit
48ac38ec9b
@ -267,6 +267,10 @@ class BufferT {
|
||||
typename std::enable_if<
|
||||
internal::BufferCompat<T, U>::value>::type* = nullptr>
|
||||
void AppendData(const U* data, size_t size) {
|
||||
if (!data) {
|
||||
RTC_CHECK_EQ(size, 0U);
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK(IsConsistent());
|
||||
const size_t new_size = size_ + size;
|
||||
EnsureCapacityWithHeadroom(new_size, true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user