1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <windows.h> 6 7 #include "base/command_line.h" 8 #include "base/files/file_path.h" 9 #include "base/process/launch.h" 10 #include "base/process/process.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 13 namespace { 14 15 // Run a Rust executable that attempts to call a function through an invalid 16 // pointer. This triggers a control flow guard exception and exits the process 17 // with STATUS_STACK_BUFFER_OVERRUN. TEST(RustCfgWin,CfgCatchesInvalidIndirectCall)18TEST(RustCfgWin, CfgCatchesInvalidIndirectCall) { 19 base::LaunchOptions o; 20 o.start_hidden = true; 21 // From //build/rust/tests/test_control_flow_guard. 22 base::CommandLine cmd(base::FilePath( 23 FILE_PATH_LITERAL("test_control_flow_guard.exe"))); 24 base::Process proc = base::LaunchProcess(cmd, o); 25 int exit_code; 26 EXPECT_TRUE(proc.WaitForExit(&exit_code)); 27 const auto u_exit_code = static_cast<unsigned long>(exit_code); 28 EXPECT_EQ(u_exit_code, STATUS_STACK_BUFFER_OVERRUN); 29 } 30 31 } // namespace 32