Skip to content

Commit f5e86b3

Browse files
add explicit test for stack smashing
1 parent 35d0759 commit f5e86b3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

libc/test/src/compiler/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ add_libc_unittest(
88
stack_chk_guard_test.cpp
99
DEPENDS
1010
libc.src.compiler.__stack_chk_fail
11+
libc.src.string.memset
12+
COMPILE_OPTIONS
13+
-fstack-protector-all
1114
)

libc/test/src/compiler/stack_chk_guard_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@
99
#include "llvm-libc-macros/signal-macros.h"
1010
#include "src/compiler/__stack_chk_fail.h"
1111
#include "test/UnitTest/Test.h"
12+
#include "src/string/memset.h"
1213

1314
TEST(LlvmLibcStackChkFail, Death) {
1415
EXPECT_DEATH([] { LIBC_NAMESPACE::__stack_chk_fail(); },
1516
WITH_SIGNAL(SIGABRT));
1617
}
18+
19+
TEST(LlvmLibcStackChkFail, Smash) {
20+
EXPECT_DEATH([] {
21+
int arr [20];
22+
LIBC_NAMESPACE::memset(arr, 0xAA, 9001);
23+
}, WITH_SIGNAL(SIGABRT));
24+
}

0 commit comments

Comments
 (0)