diff options
author | Nick Kralevich <nnk@google.com> | 2013-07-01 10:04:18 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-07-01 10:04:18 -0700 |
commit | 4b17283c9839ddd8c692eb57f657abf3facb73d8 (patch) | |
tree | e267d524323c677f2bbb04797b066d10c1a16bb4 /tests | |
parent | 22570f51a5fb8ff7015eaf22dfaf4d224411bd24 (diff) | |
parent | 28d298a673da4367f27f428db5e12d7dad3d8e83 (diff) | |
download | bionic-4b17283c9839ddd8c692eb57f657abf3facb73d8.zip bionic-4b17283c9839ddd8c692eb57f657abf3facb73d8.tar.gz bionic-4b17283c9839ddd8c692eb57f657abf3facb73d8.tar.bz2 |
am 28d298a6: am 413eef71: Merge "More FORTIFY_SOURCE functions under clang"
* commit '28d298a673da4367f27f428db5e12d7dad3d8e83':
More FORTIFY_SOURCE functions under clang
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fortify_test.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp index 68b5517..d8f0e76 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); |