Add strncpy FORTIFY_SOURCE tests.

Change-Id: Id108b1d72b44d7e5fb911268e80bbdf896808f60
This commit is contained in:
Nick Kralevich
2013-05-30 13:21:14 -07:00
parent d515f46888
commit 8cc145edf4
2 changed files with 48 additions and 0 deletions

View File

@@ -60,3 +60,19 @@ TEST(Fortify1_DeathTest, sprintf_fortified) {
memcpy(source_buf, "12345678901234", 15);
ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGSEGV), "");
}
TEST(Fortify1_DeathTest, strncat_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
size_t n = atoi("10"); // avoid compiler optimizations
strncpy(buf, "012345678", n);
ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGSEGV), "");
}
TEST(Fortify1_DeathTest, strncat2_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
buf[0] = '\0';
size_t n = atoi("10"); // avoid compiler optimizations
ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGSEGV), "");
}