summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Andrei Polushin <polushin@gmail.com>2023-06-12 17:52:54 +0700
committerGravatar Andrei Polushin EXT <polushin@gmail.com>2023-06-12 18:01:51 +0700
commitfc7467b0182914102a97f6dd7e83ae1f8927eb2a (patch)
treeb312548ce31ecbff2505eb5d4ae94f697adb86e2
parent1feab4fff90f904518e66cf80971063486fbc984 (diff)
Fix buffer overflow in a placement `new[]` storage test.
AppleClang seem to allocate two extra 64-bit words per each `new[]`. A test should pass larger buffer to a placement `new[]`. Fixes #1090
-rw-r--r--absl/base/exception_safety_testing_test.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/absl/base/exception_safety_testing_test.cc b/absl/base/exception_safety_testing_test.cc
index a87fd6a9..7c0007ad 100644
--- a/absl/base/exception_safety_testing_test.cc
+++ b/absl/base/exception_safety_testing_test.cc
@@ -332,13 +332,16 @@ TEST(ThrowingValueTest, NonThrowingPlacementDelete) {
constexpr int kArrayLen = 2;
// We intentionally create extra space to store the tag allocated by placement
// new[].
- constexpr int kStorageLen = 4;
+ constexpr size_t kExtraSpaceLen = sizeof(size_t) * 2;
alignas(ThrowingValue<>) unsigned char buf[sizeof(ThrowingValue<>)];
alignas(ThrowingValue<>) unsigned char
- array_buf[sizeof(ThrowingValue<>[kStorageLen])];
+ array_buf[kExtraSpaceLen + sizeof(ThrowingValue<>[kArrayLen])];
auto* placed = new (&buf) ThrowingValue<>(1);
auto placed_array = new (&array_buf) ThrowingValue<>[kArrayLen];
+ auto* placed_array_end = reinterpret_cast<unsigned char*>(placed_array) +
+ sizeof(ThrowingValue<>[kArrayLen]);
+ EXPECT_LE(placed_array_end, array_buf + sizeof(array_buf));
SetCountdown();
ExpectNoThrow([placed, &buf]() {