From d0447f23b851b8e13052a35f1cd7de5f4ab44a03 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 30 Jun 2021 22:40:03 -0600 Subject: Tests+Base: Convert stack-smash to be LibTest based and stop skipping it Now that the test is converted to be LibTest based, we can remove it from the exclude list in /home/anon/.config/Tests.ini. Prior to this it would crash and fail because it was signaled instead of returning normally with exit code 0. --- Base/home/anon/.config/Tests.ini | 2 +- Tests/LibC/CMakeLists.txt | 1 + Tests/LibC/TestStackSmash.cpp | 36 ++++++++++++++++++++++++++++++++++++ Tests/LibC/stack-smash.cpp | 34 ---------------------------------- 4 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 Tests/LibC/TestStackSmash.cpp delete mode 100644 Tests/LibC/stack-smash.cpp diff --git a/Base/home/anon/.config/Tests.ini b/Base/home/anon/.config/Tests.ini index f549dad980..550a26eeba 100644 --- a/Base/home/anon/.config/Tests.ini +++ b/Base/home/anon/.config/Tests.ini @@ -1,6 +1,6 @@ [Global] SkipDirectories=Kernel/Legacy UserEmulator -SkipTests=stack-smash test-web +SkipTests=test-web NotTestsPattern=.txt|.frm|.inc [test-js] diff --git a/Tests/LibC/CMakeLists.txt b/Tests/LibC/CMakeLists.txt index a4f8a4ce0b..3c5dc09d43 100644 --- a/Tests/LibC/CMakeLists.txt +++ b/Tests/LibC/CMakeLists.txt @@ -7,6 +7,7 @@ set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/TestLibCDirEnt.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TestLibCInodeWatcher.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TestLibCString.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TestStackSmash.cpp ) file(GLOB CMD_SOURCES CONFIGURE_DEPENDS "*.cpp") diff --git a/Tests/LibC/TestStackSmash.cpp b/Tests/LibC/TestStackSmash.cpp new file mode 100644 index 0000000000..bcea97d501 --- /dev/null +++ b/Tests/LibC/TestStackSmash.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021, Brian Gianforcaro + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +// Note: Needs to be 'noline' so stack canary isn't optimized out. +static void __attribute__((noinline)) smasher(char* string) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + for (int i = 0; i < 256; i++) { + string[i] = 'A'; + } +#pragma GCC diagnostic pop +} + +// Note: Needs to be 'noline' so stack canary isn't optimized out. +static void __attribute__((noinline)) stack_to_smash() +{ + char string[8] = {}; + smasher(string); +} + +TEST_CASE(stack_smash) +{ + EXPECT_CRASH("Smash the stack and trigger __stack_chk_fail", [] { + outln("[+] Starting the stack smash..."); + stack_to_smash(); + outln("[+] Stack smash wasn't detected!"); + return Test::Crash::Failure::DidNotCrash; + }); +} diff --git a/Tests/LibC/stack-smash.cpp b/Tests/LibC/stack-smash.cpp deleted file mode 100644 index 6a2a303951..0000000000 --- a/Tests/LibC/stack-smash.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021, Brian Gianforcaro - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -// Note: Needs to be 'noline' so stack canary isn't optimized out. -static void __attribute__((noinline)) smasher(char* string) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" - for (int i = 0; i < 256; i++) { - string[i] = 'A'; - } -#pragma GCC diagnostic pop -} - -// Note: Needs to be 'noline' so stack canary isn't optimized out. -static void __attribute__((noinline)) stack_to_smash() -{ - char string[8] = {}; - smasher(string); -} - -int main() -{ - puts("[+] Starting the stack smash..."); - stack_to_smash(); - puts("[+] Stack smash wasn't detected!"); - - return 0; -} -- cgit v1.2.3