diff options
author | Nick Kralevich <nnk@google.com> | 2013-01-10 17:12:29 -0800 |
---|---|---|
committer | Nick Kralevich <nnk@google.com> | 2013-01-11 10:52:36 -0800 |
commit | dcab1b2c76a498c56bc00024613386de8b4b2aae (patch) | |
tree | 6d7eb1ea166186df3092552b190b4485658b3e68 /tests/string_test.cpp | |
parent | bfde0b6fd9e5de545746ab963d3a05ed2a8014f6 (diff) | |
download | bionic-dcab1b2c76a498c56bc00024613386de8b4b2aae.zip bionic-dcab1b2c76a498c56bc00024613386de8b4b2aae.tar.gz bionic-dcab1b2c76a498c56bc00024613386de8b4b2aae.tar.bz2 |
Add stack canaries / strcpy tests.
Add a test to ensure that stack canaries are working
correctly. Since stack canaries aren't normally generated
on non-string functions, we have to enable stack-protector-all.
Add a test to ensure that an out of bounds strcpy generates
a runtime failure.
Change-Id: Id0d3e59fc4b9602da019e4d35c5c653e1a57fae4
Diffstat (limited to 'tests/string_test.cpp')
-rw-r--r-- | tests/string_test.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp index d55771c..3f7d500 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -305,6 +305,19 @@ TEST(string, strcpy) { } } + +#if __BIONIC__ +// We have to say "DeathTest" here so gtest knows to run this test (which exits) +// in its own process. +TEST(string_DeathTest, strcpy_fortified) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + char buf[10]; + char *orig = strdup("0123456789"); + ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGSEGV), ""); + free(orig); +} +#endif + #if __BIONIC__ TEST(string, strlcat) { StringTestState state(SMALL); |