Add tests for __strcpy_chk()

Change-Id: I5675d04fcd471732c1b87b83879a54fbcd27762e
This commit is contained in:
Nick Kralevich
2013-06-03 10:58:06 -07:00
parent 0671393072
commit 13476deec4
3 changed files with 136 additions and 0 deletions

View File

@@ -23,6 +23,8 @@
#if __BIONIC__
// We have to say "DeathTest" here so gtest knows to run this test (which exits)
// in its own process.
// multibyte target where we over fill (should fail)
TEST(Fortify1_DeathTest, strcpy_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
@@ -31,6 +33,33 @@ TEST(Fortify1_DeathTest, strcpy_fortified) {
free(orig);
}
// zero sized target with "\0" source (should fail)
TEST(Fortify1_DeathTest, strcpy2_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0];
char *orig = strdup("");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGSEGV), "");
free(orig);
}
// zero sized target with longer source (should fail)
TEST(Fortify1_DeathTest, strcpy3_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0];
char *orig = strdup("1");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGSEGV), "");
free(orig);
}
// one byte target with longer source (should fail)
TEST(Fortify1_DeathTest, strcpy4_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1];
char *orig = strdup("12");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGSEGV), "");
free(orig);
}
TEST(Fortify1_DeathTest, strlen_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];