| Index: base/security_unittest.cc
|
| diff --git a/base/security_unittest.cc b/base/security_unittest.cc
|
| index 07ba6f5a0f2af7fed188fa441beffa601c8a2bb3..cea27175cf62bf1e4c93ddd942071d2fe28fb707 100644
|
| --- a/base/security_unittest.cc
|
| +++ b/base/security_unittest.cc
|
| @@ -23,47 +23,11 @@
|
| #include <unistd.h>
|
| #endif
|
|
|
| -#if defined(OS_WIN)
|
| -#include <new.h>
|
| -#endif
|
| -
|
| using std::nothrow;
|
| using std::numeric_limits;
|
|
|
| namespace {
|
|
|
| -#if defined(OS_WIN)
|
| -// This is a permitted size but exhausts memory pretty quickly.
|
| -const size_t kLargePermittedAllocation = 0x7FFFE000;
|
| -
|
| -int OnNoMemory(size_t) {
|
| - _exit(1);
|
| -}
|
| -
|
| -void ExhaustMemoryWithMalloc() {
|
| - for (;;) {
|
| - // Without the |volatile|, clang optimizes away the allocation.
|
| - void* volatile buf = malloc(kLargePermittedAllocation);
|
| - if (!buf)
|
| - break;
|
| - }
|
| -}
|
| -
|
| -void ExhaustMemoryWithRealloc() {
|
| - size_t size = kLargePermittedAllocation;
|
| - void* buf = malloc(size);
|
| - if (!buf)
|
| - return;
|
| - for (;;) {
|
| - size += kLargePermittedAllocation;
|
| - void* new_buf = realloc(buf, size);
|
| - if (!buf)
|
| - break;
|
| - buf = new_buf;
|
| - }
|
| -}
|
| -#endif
|
| -
|
| // This function acts as a compiler optimization barrier. We use it to
|
| // prevent the compiler from making an expression a compile-time constant.
|
| // We also use it so that the compiler doesn't discard certain return values
|
| @@ -140,42 +104,6 @@ TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationRestrictionsMalloc)) {
|
| }
|
| }
|
|
|
| -#if defined(GTEST_HAS_DEATH_TEST) && defined(OS_WIN)
|
| -TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationMallocDeathTest)) {
|
| - _set_new_handler(&OnNoMemory);
|
| - _set_new_mode(1);
|
| - {
|
| - scoped_ptr<char, base::FreeDeleter> ptr;
|
| - EXPECT_DEATH(ptr.reset(static_cast<char*>(
|
| - HideValueFromCompiler(malloc(kTooBigAllocSize)))),
|
| - "");
|
| - ASSERT_TRUE(!ptr);
|
| - }
|
| - _set_new_handler(NULL);
|
| - _set_new_mode(0);
|
| -}
|
| -
|
| -TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationExhaustDeathTest)) {
|
| - _set_new_handler(&OnNoMemory);
|
| - _set_new_mode(1);
|
| - {
|
| - ASSERT_DEATH(ExhaustMemoryWithMalloc(), "");
|
| - }
|
| - _set_new_handler(NULL);
|
| - _set_new_mode(0);
|
| -}
|
| -
|
| -TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryReallocationExhaustDeathTest)) {
|
| - _set_new_handler(&OnNoMemory);
|
| - _set_new_mode(1);
|
| - {
|
| - ASSERT_DEATH(ExhaustMemoryWithRealloc(), "");
|
| - }
|
| - _set_new_handler(NULL);
|
| - _set_new_mode(0);
|
| -}
|
| -#endif
|
| -
|
| TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationRestrictionsCalloc)) {
|
| if (!IsTcMallocBypassed()) {
|
| scoped_ptr<char, base::FreeDeleter> ptr(static_cast<char*>(
|
| @@ -208,19 +136,6 @@ TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationRestrictionsNew)) {
|
| }
|
| }
|
|
|
| -#if defined(GTEST_HAS_DEATH_TEST) && defined(OS_WIN)
|
| -TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationNewDeathTest)) {
|
| - _set_new_handler(&OnNoMemory);
|
| - {
|
| - scoped_ptr<VeryLargeStruct> ptr;
|
| - EXPECT_DEATH(
|
| - ptr.reset(HideValueFromCompiler(new (nothrow) VeryLargeStruct)), "");
|
| - ASSERT_TRUE(!ptr);
|
| - }
|
| - _set_new_handler(NULL);
|
| -}
|
| -#endif
|
| -
|
| TEST(SecurityTest, MALLOC_OVERFLOW_TEST(MemoryAllocationRestrictionsNewArray)) {
|
| if (!IsTcMallocBypassed()) {
|
| scoped_ptr<char[]> ptr(
|
| @@ -249,7 +164,7 @@ void OverflowTestsSoftExpectTrue(bool overflow_detected) {
|
| }
|
| }
|
|
|
| -#if defined(OS_IOS) || defined(OS_WIN) || defined(THREAD_SANITIZER) || defined(OS_MACOSX)
|
| +#if defined(OS_IOS) || defined(THREAD_SANITIZER) || defined(OS_MACOSX)
|
| #define MAYBE_NewOverflow DISABLED_NewOverflow
|
| #else
|
| #define MAYBE_NewOverflow NewOverflow
|
| @@ -274,17 +189,11 @@ TEST(SecurityTest, MAYBE_NewOverflow) {
|
| char[kDynamicArraySize2][kArraySize]);
|
| OverflowTestsSoftExpectTrue(!array_pointer);
|
| }
|
| - // On windows, the compiler prevents static array sizes of more than
|
| - // 0x7fffffff (error C2148).
|
| -#if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
|
| - ALLOW_UNUSED_LOCAL(kDynamicArraySize);
|
| -#else
|
| {
|
| scoped_ptr<char[][kArraySize2]> array_pointer(new (nothrow)
|
| char[kDynamicArraySize][kArraySize2]);
|
| OverflowTestsSoftExpectTrue(!array_pointer);
|
| }
|
| -#endif // !defined(OS_WIN) || !defined(ARCH_CPU_64_BITS)
|
| }
|
|
|
| // Call calloc(), eventually free the memory and return whether or not
|
|
|