aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fortify2_test_clang.cpp
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-06-27 08:58:14 -0700
committerNick Kralevich <nnk@google.com>2013-06-27 09:17:48 -0700
commitc8ae8bd9418b79f4da85dc12a61ebd82146b7e51 (patch)
tree993d68a67de1e710dc393dd70e61775057ad22c3 /tests/fortify2_test_clang.cpp
parentfbec57d46c42460b2381484d1610ff21922d162e (diff)
downloadandroid_bionic-c8ae8bd9418b79f4da85dc12a61ebd82146b7e51.tar.gz
android_bionic-c8ae8bd9418b79f4da85dc12a61ebd82146b7e51.tar.bz2
android_bionic-c8ae8bd9418b79f4da85dc12a61ebd82146b7e51.zip
stdio.h: enable vs?printf clang FORTIFY_SOURCE
Enable FORTIFY_SOURCE protections under clang for the following functions: * vsprintf * vsnprintf and add unittests. Change-Id: I90f8a27f7b202c78b5dd8ebf53050bf9e33496f7
Diffstat (limited to 'tests/fortify2_test_clang.cpp')
-rw-r--r--tests/fortify2_test_clang.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/fortify2_test_clang.cpp b/tests/fortify2_test_clang.cpp
index 7183bc0ce..83f57e8f4 100644
--- a/tests/fortify2_test_clang.cpp
+++ b/tests/fortify2_test_clang.cpp
@@ -19,6 +19,7 @@
#include <gtest/gtest.h>
#include <string.h>
+#include <stdarg.h>
struct foo {
char empty[0];
@@ -123,6 +124,49 @@ TEST(Fortify2_Clang_DeathTest, sprintf2_fortified) {
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
}
+static int vsprintf_helper(const char *fmt, ...) {
+ char buf[10];
+ va_list va;
+ int result;
+
+ va_start(va, fmt);
+ result = vsprintf(buf, fmt, va); // should crash here
+ va_end(va);
+ return result;
+}
+
+TEST(Fortify2_Clang_DeathTest, vsprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ ASSERT_EXIT(vsprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
+}
+
+TEST(Fortify2_Clang_DeathTest, vsprintf2_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ ASSERT_EXIT(vsprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
+}
+
+static int vsnprintf_helper(const char *fmt, ...) {
+ char buf[10];
+ va_list va;
+ int result;
+ size_t size = atoi("11");
+
+ va_start(va, fmt);
+ result = vsnprintf(buf, size, fmt, va); // should crash here
+ va_end(va);
+ return result;
+}
+
+TEST(Fortify2_Clang_DeathTest, vsnprintf_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ ASSERT_EXIT(vsnprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
+}
+
+TEST(Fortify2_Clang_DeathTest, vsnprintf2_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ ASSERT_EXIT(vsnprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
+}
+
TEST(Fortify2_Clang_DeathTest, strncat_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];