From 656fc625893ee8376c8cd9d9145925056cef322b Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 7 Jun 2023 20:38:09 +0000 Subject: [PATCH] [snapshot] Suppress function type mismatch UB UBSan is detecting a function type mismatch in this test. This is because TestModule_GetCrashpadInfo returns a TestCrashpadInfo* but the function expectes to return a CrashpadInfo*. Structurally, the TestCrashpadInfo struct is meant to replicate a CrashpadInfo byte-for-byte, but there's no relationship between the types. Bug: fxbug.dev/128274 Change-Id: I7b02ca802e55274116d46513b3aa6dc998f6d292 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4599482 Reviewed-by: Mark Mentovai --- snapshot/crashpad_info_client_options_test.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/snapshot/crashpad_info_client_options_test.cc b/snapshot/crashpad_info_client_options_test.cc index bc097902..005dfd59 100644 --- a/snapshot/crashpad_info_client_options_test.cc +++ b/snapshot/crashpad_info_client_options_test.cc @@ -241,6 +241,22 @@ TEST(CrashpadInfoClientOptions, TwoModules) { class CrashpadInfoSizes_ClientOptions : public testing::TestWithParam {}; +// UBSan detects a function type mismatch when calling +// TestModule_GetCrashpadInfo since the expected function signature should +// return a CrashpadInfo* but the actual TestModule_GetCrashpadInfo defined for +// the test returns a TestCrashpadInfo*. CrashpadInfo is a struct with its +// members set as private and TestCrashpadInfo is a POD meant to replicate the +// layout of CrashpadInfo byte-for-byte. Note this is intentional since the +// whole point of the test is to exercise the snapshot reader’s ability to +// handle CrashpadInfo. +#if defined(__clang__) +[[clang::no_sanitize("function")]] +#endif +inline CrashpadInfo* +CallGetCrashpadInfo(CrashpadInfo* (*func)()) { + return func(); +} + TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) { base::FilePath::StringType artifact(FILE_PATH_LITERAL("module_")); artifact += GetParam(); @@ -279,7 +295,8 @@ TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) { EXPECT_EQ(options.gather_indirectly_referenced_memory, TriState::kUnset); // Get the remote CrashpadInfo structure. - CrashpadInfo* remote_crashpad_info = TestModule_GetCrashpadInfo(); + CrashpadInfo* remote_crashpad_info = + CallGetCrashpadInfo(TestModule_GetCrashpadInfo); ASSERT_TRUE(remote_crashpad_info); {