am 95de0df8: am eda2679e: Merge "FORTIFY_SOURCE: fortify read()"

* commit '95de0df8c2daeefca358010f2d15c3346a5284f1':
  FORTIFY_SOURCE: fortify read()
This commit is contained in:
Nick Kralevich
2013-10-09 21:28:52 -07:00
committed by Android Git Automerger
4 changed files with 87 additions and 0 deletions

View File

@@ -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);