am 69c89942: Merge "Add stack canaries / strcpy tests."

* commit '69c89942db2ed472c71aa84903d0259cc84aa074':
  Add stack canaries / strcpy tests.
This commit is contained in:
Nick Kralevich 2013-01-11 11:26:54 -08:00 committed by Android Git Automerger
commit d0f81466e4
3 changed files with 34 additions and 1 deletions

View File

@ -47,7 +47,7 @@ include $(BUILD_EXECUTABLE)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
test_c_flags = \ test_c_flags = \
-fstack-protector \ -fstack-protector-all \
-g \ -g \
-Wall -Wextra \ -Wall -Wextra \
-Werror \ -Werror \

View File

@ -114,4 +114,24 @@ TEST(stack_protector, global_guard) {
ASSERT_NE(0U, reinterpret_cast<uintptr_t>(__stack_chk_guard)); ASSERT_NE(0U, reinterpret_cast<uintptr_t>(__stack_chk_guard));
} }
/*
* When this function returns, the stack canary will be inconsistent
* with the previous value, which will generate a call to __stack_chk_fail(),
* eventually resulting in a SIGABRT.
*
* This must be marked with "__attribute__ ((noinline))", to ensure the
* compiler generates the proper stack guards around this function.
*/
__attribute__ ((noinline))
static void do_modify_stack_chk_guard() {
__stack_chk_guard = (void *) 0x12345678;
}
// We have to say "DeathTest" here so gtest knows to run this test (which exits)
// in its own process.
TEST(stack_protector_DeathTest, modify_stack_protector) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
}
#endif #endif

View File

@ -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__ #if __BIONIC__
TEST(string, strlcat) { TEST(string, strlcat) {
StringTestState state(SMALL); StringTestState state(SMALL);