From aef7de4e93b89e58f84888e6a4552fcd833e7630 Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Wed, 17 Jul 2024 04:27:51 +0000 Subject: [PATCH] [MSan] "Fix" use-after-dtor in InitializationState.InitializationState Since the test is specifically trying to exercise UB by testing the state of an object it is already destroyed, unpoison the memory to suppress MSan errors. Bug: 40222690 Change-Id: I840e944f5e8b39668ac05d8d641fdd5f2e3db5ac Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5716150 Reviewed-by: Mark Mentovai --- util/misc/initialization_state_test.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/misc/initialization_state_test.cc b/util/misc/initialization_state_test.cc index f3681173..d6b96ced 100644 --- a/util/misc/initialization_state_test.cc +++ b/util/misc/initialization_state_test.cc @@ -18,6 +18,7 @@ #include +#include "base/compiler_specific.h" #include "base/memory/free_deleter.h" #include "gtest/gtest.h" @@ -59,6 +60,10 @@ TEST(InitializationState, InitializationState) { // buffer that’s still valid and its destructor was called directly, this // approximates use-after-free without risking that the memory formerly used // for the InitializationState object has been repurposed. + + // (Though this is still UB and MSan does not like this) + MSAN_UNPOISON(initialization_state, sizeof(*initialization_state)); + EXPECT_FALSE(initialization_state->is_uninitialized()); EXPECT_FALSE(initialization_state->is_valid()); }