From 84c87739e837f4ec9ce26f32f693e3dddd6494ad Mon Sep 17 00:00:00 2001 From: danakj Date: Mon, 6 May 2024 09:54:31 -0400 Subject: [PATCH] Use the span version of RandBytes Some unique_ptr are also changed to HeapArray in order to facilitate the change. Bug: chromuim: 40284755 Change-Id: I30b9d55ff81f23c63ad4958786740f67ee612024 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5512569 Reviewed-by: Mark Mentovai Commit-Queue: danakj --- DEPS | 2 +- util/misc/uuid.cc | 2 +- util/stream/base94_output_stream_test.cc | 18 +++++++++--------- util/stream/zlib_output_stream_test.cc | 18 +++++++++--------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/DEPS b/DEPS index 1384fdd1..e5e137e1 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '8b56c7718412ec7d12d05522f7af0cbb787cbb00', + 'f3bf9dce1e62c8ab8c15130c9829255879cd0e4d', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc index af33df51..fb27f27c 100644 --- a/util/misc/uuid.cc +++ b/util/misc/uuid.cc @@ -116,7 +116,7 @@ bool UUID::InitializeWithNew() { // from libuuid is not available everywhere. // On Windows, do not use UuidCreate() to avoid a dependency on rpcrt4, so // that this function is usable early in DllMain(). - base::RandBytes(this, sizeof(*this)); + base::RandBytes(base::byte_span_from_ref(*this)); // Set six bits per RFC 4122 §4.4 to identify this as a pseudo-random UUID. data_3 = (4 << 12) | (data_3 & 0x0fff); // §4.1.3 diff --git a/util/stream/base94_output_stream_test.cc b/util/stream/base94_output_stream_test.cc index 1043840d..09f6b009 100644 --- a/util/stream/base94_output_stream_test.cc +++ b/util/stream/base94_output_stream_test.cc @@ -20,6 +20,7 @@ #include #include +#include "base/containers/heap_array.h" #include "base/rand_util.h" #include "base/strings/stringprintf.h" #include "gtest/gtest.h" @@ -71,17 +72,16 @@ class Base94OutputStreamTest : public testing::Test { } const uint8_t* BuildDeterministicInput(size_t size) { - deterministic_input_ = std::make_unique(size); - uint8_t* deterministic_input_base = deterministic_input_.get(); + deterministic_input_ = base::HeapArray::WithSize(size); while (size-- > 0) - deterministic_input_base[size] = static_cast(size); - return deterministic_input_base; + deterministic_input_[size] = static_cast(size); + return deterministic_input_.data(); } const uint8_t* BuildRandomInput(size_t size) { - input_ = std::make_unique(size); - base::RandBytes(&input_[0], size); - return input_.get(); + input_ = base::HeapArray::Uninit(size); + base::RandBytes(input_); + return input_.data(); } Base94OutputStream* round_trip() const { return round_trip_.get(); } @@ -127,8 +127,8 @@ class Base94OutputStreamTest : public testing::Test { TestOutputStream* encode_test_output_stream_; TestOutputStream* decode_test_output_stream_; TestOutputStream* round_trip_test_output_stream_; - std::unique_ptr input_; - std::unique_ptr deterministic_input_; + base::HeapArray input_; + base::HeapArray deterministic_input_; }; TEST_F(Base94OutputStreamTest, Encoding) { diff --git a/util/stream/zlib_output_stream_test.cc b/util/stream/zlib_output_stream_test.cc index 76885168..25de62ad 100644 --- a/util/stream/zlib_output_stream_test.cc +++ b/util/stream/zlib_output_stream_test.cc @@ -19,6 +19,7 @@ #include #include +#include "base/containers/heap_array.h" #include "base/rand_util.h" #include "base/strings/stringprintf.h" #include "gtest/gtest.h" @@ -46,17 +47,16 @@ class ZlibOutputStreamTest : public testing::Test { ZlibOutputStreamTest& operator=(const ZlibOutputStreamTest&) = delete; const uint8_t* BuildDeterministicInput(size_t size) { - deterministic_input_ = std::make_unique(size); - uint8_t* deterministic_input_base = deterministic_input_.get(); + deterministic_input_ = base::HeapArray::WithSize(size); while (size-- > 0) - deterministic_input_base[size] = static_cast(size); - return deterministic_input_base; + deterministic_input_[size] = static_cast(size); + return deterministic_input_.data(); } const uint8_t* BuildRandomInput(size_t size) { - input_ = std::make_unique(size); - base::RandBytes(&input_[0], size); - return input_.get(); + input_ = base::HeapArray::Uninit(size); + base::RandBytes(input_); + return input_.data(); } const TestOutputStream& test_output_stream() const { @@ -69,8 +69,8 @@ class ZlibOutputStreamTest : public testing::Test { private: std::unique_ptr zlib_output_stream_; - std::unique_ptr input_; - std::unique_ptr deterministic_input_; + base::HeapArray input_; + base::HeapArray deterministic_input_; TestOutputStream* test_output_stream_; // weak, owned by zlib_output_stream_ };