diff options
author | Nick Kralevich <nnk@google.com> | 2013-01-17 15:41:33 -0800 |
---|---|---|
committer | Nick Kralevich <nnk@google.com> | 2013-01-17 15:41:33 -0800 |
commit | a44e9afdd16105d6f36319cb538666d9cc78435a (patch) | |
tree | 8606530bcdef438dc305894c805f0713edad5306 /tests | |
parent | f3fe19459fd9263e8cc8a413a5313b1ec3cf3975 (diff) | |
download | bionic-a44e9afdd16105d6f36319cb538666d9cc78435a.zip bionic-a44e9afdd16105d6f36319cb538666d9cc78435a.tar.gz bionic-a44e9afdd16105d6f36319cb538666d9cc78435a.tar.bz2 |
FORTIFY_SOURCE: optimize
Don't do the fortify_source checks if we can determine, at
compile time, that the provided operation is safe.
This avoids silliness like calling fortify source on things like:
size_t len = strlen("asdf");
printf("%d\n", len);
and allows the compiler to optimize this code to:
printf("%d\n", 4);
Defer to gcc's builtin functions instead of pointing our code
to the libc implementation.
Change-Id: I5e1dcb61946461c4afaaaa983e39f07c7a0df0ae
Diffstat (limited to 'tests')
-rw-r--r-- | tests/string_test.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 08c73a1..1720058 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -316,6 +316,27 @@ TEST(string_DeathTest, strcpy_fortified) { ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGSEGV), ""); free(orig); } + +TEST(string_DeathTest, strlen_fortified) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + char buf[10]; + memcpy(buf, "0123456789", sizeof(buf)); + ASSERT_EXIT(printf("%d", strlen(buf)), testing::KilledBySignal(SIGSEGV), ""); +} + +TEST(string_DeathTest, strchr_fortified) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + char buf[10]; + memcpy(buf, "0123456789", sizeof(buf)); + ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGSEGV), ""); +} + +TEST(string_DeathTest, strrchr_fortified) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + char buf[10]; + memcpy(buf, "0123456789", sizeof(buf)); + ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGSEGV), ""); +} #endif #if __BIONIC__ |