libc: enable FORTIFY_SOURCE snprintf under clang
Change-Id: I8b8059782a720104722b0841994b38f873ed02aa
diff --git a/tests/fortify1_test.cpp b/tests/fortify1_test.cpp
index 9d40404..afc9b11 100644
--- a/tests/fortify1_test.cpp
+++ b/tests/fortify1_test.cpp
@@ -157,6 +157,15 @@
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
}
+TEST(Fortify1_DeathTest, snprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char bufa[15];
+ char bufb[10];
+ strcpy(bufa, "0123456789");
+ size_t n = strlen(bufa) + 1;
+ ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
+}
+
extern "C" char* __strncat_chk(char*, const char*, size_t, size_t);
extern "C" char* __strcat_chk(char*, const char*, size_t);
diff --git a/tests/fortify1_test_clang.cpp b/tests/fortify1_test_clang.cpp
index b4ded33..9f5b8b5 100644
--- a/tests/fortify1_test_clang.cpp
+++ b/tests/fortify1_test_clang.cpp
@@ -157,6 +157,15 @@
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
}
+TEST(Fortify1_Clang_DeathTest, snprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char bufa[15];
+ char bufb[10];
+ strcpy(bufa, "0123456789");
+ size_t n = strlen(bufa) + 1;
+ ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
+}
+
extern "C" char* __strncat_chk(char*, const char*, size_t, size_t);
extern "C" char* __strcat_chk(char*, const char*, size_t);
diff --git a/tests/fortify2_test.cpp b/tests/fortify2_test.cpp
index 2f50038..9a13612 100644
--- a/tests/fortify2_test.cpp
+++ b/tests/fortify2_test.cpp
@@ -155,6 +155,14 @@
ASSERT_EXIT(strcat(myfoo.b, myfoo.a), testing::KilledBySignal(SIGABRT), "");
}
+TEST(Fortify2_DeathTest, snprintf_fortified2) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ foo myfoo;
+ strcpy(myfoo.a, "012345678");
+ size_t n = strlen(myfoo.a) + 2;
+ ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), "");
+}
+
/***********************************************************/
/* TESTS BELOW HERE DUPLICATE TESTS FROM fortify1_test.cpp */
/***********************************************************/
@@ -292,3 +300,12 @@
size_t n = strlen(bufa);
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
}
+
+TEST(Fortify2_DeathTest, snprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char bufa[15];
+ char bufb[10];
+ strcpy(bufa, "0123456789");
+ size_t n = strlen(bufa) + 1;
+ ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
+}
diff --git a/tests/fortify2_test_clang.cpp b/tests/fortify2_test_clang.cpp
index 54a6e5a..7183bc0 100644
--- a/tests/fortify2_test_clang.cpp
+++ b/tests/fortify2_test_clang.cpp
@@ -174,6 +174,15 @@
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
}
+TEST(Fortify2_Clang_DeathTest, snprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char bufa[15];
+ char bufb[10];
+ strcpy(bufa, "0123456789");
+ size_t n = strlen(bufa) + 1;
+ ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
+}
+
__BIONIC_FORTIFY_INLINE
size_t test_fortify2_inline(char* buf) {
return __bos(buf);