mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Prevent UB on BufferT::AppendData and ctor.
While [1] partially fixed the problem, UB was still possible when AppendData was called with size=0 or in one of the constructors. [1] - https://webrtc-review.googlesource.com/c/src/+/271502 Bug: webrtc:14292 Change-Id: I9196e23687ee82b7bfbe1ed43460d9f99adcd1ee Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271980 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37814}
This commit is contained in:
parent
b9201b0ef4
commit
7103e7085f
1 changed files with 6 additions and 3 deletions
|
@ -106,7 +106,10 @@ class BufferT {
|
|||
internal::BufferCompat<T, U>::value>::type* = nullptr>
|
||||
BufferT(U* data, size_t size, size_t capacity) : BufferT(size, capacity) {
|
||||
static_assert(sizeof(T) == sizeof(U), "");
|
||||
std::memcpy(data_.get(), data, size * sizeof(U));
|
||||
if (size > 0) {
|
||||
RTC_DCHECK(data);
|
||||
std::memcpy(data_.get(), data, size * sizeof(U));
|
||||
}
|
||||
}
|
||||
|
||||
// Construct a buffer from the contents of an array.
|
||||
|
@ -267,10 +270,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);
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK(data);
|
||||
RTC_DCHECK(IsConsistent());
|
||||
const size_t new_size = size_ + size;
|
||||
EnsureCapacityWithHeadroom(new_size, true);
|
||||
|
|
Loading…
Reference in a new issue