#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/gwp_asan/crash_handler/crash_handler.h"
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/page_size.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/test/gtest_util.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "components/gwp_asan/client/guarded_page_allocator.h"
#include "components/gwp_asan/client/gwp_asan.h"
#include "components/gwp_asan/client/lightweight_detector/poison_metadata_recorder.h"
#include "components/gwp_asan/common/crash_key_name.h"
#include "components/gwp_asan/common/lightweight_detector_state.h"
#include "components/gwp_asan/crash_handler/crash.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#include "third_party/crashpad/crashpad/client/annotation.h"
#include "third_party/crashpad/crashpad/client/crash_report_database.h"
#include "third_party/crashpad/crashpad/client/crashpad_client.h"
#include "third_party/crashpad/crashpad/client/crashpad_info.h"
#include "third_party/crashpad/crashpad/handler/handler_main.h"
#include "third_party/crashpad/crashpad/snapshot/minidump/process_snapshot_minidump.h"
#include "third_party/crashpad/crashpad/tools/tool_support.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include "third_party/crashpad/crashpad/snapshot/sanitized/sanitization_information.h"
#endif
namespace gwp_asan {
namespace internal {
namespace {
constexpr size_t kAllocationSize = …;
constexpr int kSuccess = …;
constexpr size_t kTotalPages = …;
#if !BUILDFLAG(IS_ANDROID)
int HandlerMainAdaptor(int argc, char* argv[]) { … }
MULTIPROCESS_TEST_MAIN(CrashpadHandler) { … }
#endif
MULTIPROCESS_TEST_MAIN(CrashingProcess) { … }
enum class ShouldSanitize : bool { … };
enum class EnableLightweightDetector : bool { … };
enum class HasAllocation : bool { … };
enum class HasDeallocation : bool { … };
struct TestParams { … };
class BaseCrashHandlerTest : public base::MultiProcessTest,
public testing::WithParamInterface<TestParams> { … };
class CrashHandlerTest : public BaseCrashHandlerTest { … };
#if defined(ADDRESS_SANITIZER) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID))
#define MAYBE_DISABLED …
#else
#define MAYBE_DISABLED(name) …
#endif
TEST_P(CrashHandlerTest, MAYBE_DISABLED(UseAfterFree)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(DoubleFree)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(Underflow)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(Overflow)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(FreeInvalidAddress)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(MissingMetadata)) { … }
TEST_P(CrashHandlerTest, MAYBE_DISABLED(UnrelatedException)) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if !defined(ADDRESS_SANITIZER) && defined(ARCH_CPU_64_BITS)
class LightweightDetectorCrashHandlerTest : public BaseCrashHandlerTest { … };
TEST_P(LightweightDetectorCrashHandlerTest, LightweightDetectorUseAfterFree) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
}
}
}