aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fortify_test.cpp
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-06-29 08:15:25 -0700
committerNick Kralevich <nnk@google.com>2013-06-29 08:16:22 -0700
commita6cde392765eb955cb4be5faa6ee62dcf77e8aa5 (patch)
treec1553a2002af8470615afecb1a2fff9c29c2f916 /tests/fortify_test.cpp
parent227b47a461b27d746b373feb66001cdddc9ba1db (diff)
downloadandroid_bionic-a6cde392765eb955cb4be5faa6ee62dcf77e8aa5.tar.gz
android_bionic-a6cde392765eb955cb4be5faa6ee62dcf77e8aa5.tar.bz2
android_bionic-a6cde392765eb955cb4be5faa6ee62dcf77e8aa5.zip
More FORTIFY_SOURCE functions under clang
* bzero * umask * strlcat Change-Id: I65065208e0b8b37e10f6a266d5305de8fa9e59fc
Diffstat (limited to 'tests/fortify_test.cpp')
-rw-r--r--tests/fortify_test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 68b5517d6..d8f0e7619 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -17,6 +17,8 @@
#include <gtest/gtest.h>
#include <string.h>
#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
// We have to say "DeathTest" here so gtest knows to run this test (which exits)
// in its own process. Unfortunately, the C preprocessor doesn't give us an
@@ -204,6 +206,20 @@ TEST(DEATHTEST, strlcpy_fortified2) {
}
#endif
+#ifndef __clang__
+// This test is disabled in clang because clang doesn't properly detect
+// this buffer overflow. TODO: Fix clang.
+TEST(DEATHTEST, strlcat_fortified2) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ foo myfoo;
+ strcpy(myfoo.a, "01");
+ myfoo.one[0] = '\0';
+ size_t n = strlen(myfoo.a);
+ ASSERT_EXIT(strlcat(myfoo.one, myfoo.a, n),
+ testing::KilledBySignal(SIGABRT), "");
+}
+#endif
+
#endif /* __BIONIC__ */
#ifndef __clang__
@@ -268,6 +284,14 @@ TEST(DEATHTEST, snprintf_fortified2) {
ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), "");
}
+TEST(DEATHTEST, bzero_fortified2) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ foo myfoo;
+ memcpy(myfoo.b, "0123456789", sizeof(myfoo.b));
+ size_t n = atoi("11");
+ ASSERT_EXIT(bzero(myfoo.b, n), testing::KilledBySignal(SIGABRT), "");
+}
+
#endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */
#if __BIONIC__
@@ -337,6 +361,16 @@ TEST(DEATHTEST, strlcpy_fortified) {
ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
}
+TEST(DEATHTEST, strlcat_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char bufa[15];
+ char bufb[10];
+ bufb[0] = '\0';
+ strcpy(bufa, "01234567890123");
+ size_t n = strlen(bufa);
+ ASSERT_EXIT(strlcat(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
+}
+
#endif
TEST(DEATHTEST, sprintf_fortified) {
@@ -456,6 +490,20 @@ TEST(DEATHTEST, snprintf_fortified) {
ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), "");
}
+TEST(DEATHTEST, bzero_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char buf[10];
+ memcpy(buf, "0123456789", sizeof(buf));
+ size_t n = atoi("11");
+ ASSERT_EXIT(bzero(buf, n), testing::KilledBySignal(SIGABRT), "");
+}
+
+TEST(DEATHTEST, umask_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ mode_t mask = atoi("1023"); // 01777 in octal
+ ASSERT_EXIT(umask(mask), 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);