blob: ba39b9ad547187e0969a8b8e4ba96b614a93ab03 [file] [log] [blame]
danakj389b8cf2023-04-03 19:55:411// 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
13namespace {
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.
18TEST(RustCfgWin, CfgCatchesInvalidIndirectCall) {
19 base::LaunchOptions o;
20 o.start_hidden = true;
danakjf3d553e2023-04-17 23:18:1721 // From //build/rust/tests/test_control_flow_guard.
Peter Kasting134ef9af2024-12-28 02:30:0922 base::CommandLine cmd(
23 base::FilePath(FILE_PATH_LITERAL("test_control_flow_guard.exe")));
danakj389b8cf2023-04-03 19:55:4124 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