aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fortify_test.cpp
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-10-09 13:44:38 -0700
committerNick Kralevich <nnk@google.com>2013-10-09 13:44:38 -0700
commit65c99de2cb7a569ea17ca35e2f8f1e033421864b (patch)
treeed12e2385af1f3a3fc350805f19b7c2948443374 /tests/fortify_test.cpp
parent777a4ee6771e6fe3362ef4f24244a44fcd0aabe4 (diff)
downloadandroid_bionic-65c99de2cb7a569ea17ca35e2f8f1e033421864b.tar.gz
android_bionic-65c99de2cb7a569ea17ca35e2f8f1e033421864b.tar.bz2
android_bionic-65c99de2cb7a569ea17ca35e2f8f1e033421864b.zip
FORTIFY_SOURCE: fortify read()
Change-Id: I3d7b4ec86d04efb865117ce7629a2e26917f3331
Diffstat (limited to 'tests/fortify_test.cpp')
-rw-r--r--tests/fortify_test.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index d514a3d10..b42c6b781 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <malloc.h>
+#include <fcntl.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
@@ -568,6 +569,15 @@ TEST(DEATHTEST, FD_ZERO_fortified) {
ASSERT_EXIT(FD_ZERO(set), testing::KilledBySignal(SIGABRT), "");
}
+TEST(DEATHTEST, read_fortified) {
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ char buf[1];
+ size_t ct = atoi("2"); // prevent optimizations
+ int fd = open("/dev/null", O_RDONLY);
+ ASSERT_EXIT(read(fd, buf, ct), testing::KilledBySignal(SIGABRT), "");
+ close(fd);
+}
+
extern "C" char* __strncat_chk(char*, const char*, size_t, size_t);
extern "C" char* __strcat_chk(char*, const char*, size_t);