danakj | 389b8cf | 2023-04-03 19:55:41 | [diff] [blame] | 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. |
| 18 | TEST(RustCfgWin, CfgCatchesInvalidIndirectCall) { |
| 19 | base::LaunchOptions o; |
| 20 | o.start_hidden = true; |
danakj | f3d553e | 2023-04-17 23:18:17 | [diff] [blame] | 21 | // From //build/rust/tests/test_control_flow_guard. |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 22 | base::CommandLine cmd( |
| 23 | base::FilePath(FILE_PATH_LITERAL("test_control_flow_guard.exe"))); |
danakj | 389b8cf | 2023-04-03 19:55:41 | [diff] [blame] | 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 |