summaryrefslogtreecommitdiffstats
path: root/base/process/memory_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/process/memory_unittest.cc')
-rw-r--r--base/process/memory_unittest.cc78
1 files changed, 73 insertions, 5 deletions
diff --git a/base/process/memory_unittest.cc b/base/process/memory_unittest.cc
index 0276b49..98f049a 100644
--- a/base/process/memory_unittest.cc
+++ b/base/process/memory_unittest.cc
@@ -30,6 +30,16 @@
#endif
#if defined(OS_WIN)
+
+#if defined(_MSC_VER)
+// ssize_t needed for OutOfMemoryTest.
+#if defined(_WIN64)
+typedef __int64 ssize_t;
+#else
+typedef long ssize_t;
+#endif
+#endif
+
// HeapQueryInformation function pointer.
typedef BOOL (WINAPI* HeapQueryFn) \
(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T, PSIZE_T);
@@ -130,8 +140,9 @@ TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
// OutOfMemoryTest cases. OpenBSD does not support these tests either.
// Don't test these on ASan/TSan/MSan configurations: only test the real
// allocator.
-// TODO(vandebo) make this work on Windows too.
-#if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) && \
+// Windows only supports these tests with the allocator shim in place.
+#if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \
+ !(defined(OS_WIN) && !defined(ALLOCATOR_SHIM)) && \
!defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
#if defined(USE_TCMALLOC)
@@ -151,6 +162,9 @@ class OutOfMemoryTest : public testing::Test {
// Make test size as large as possible minus a few pages so
// that alignment or other rounding doesn't make it wrap.
test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024),
+ // A test size that is > 2Gb and will cause the allocators to reject
+ // the allocation due to security restrictions. See crbug.com/169327.
+ insecure_test_size_(std::numeric_limits<int>::max()),
signed_test_size_(std::numeric_limits<ssize_t>::max()) {
}
@@ -163,6 +177,7 @@ class OutOfMemoryTest : public testing::Test {
protected:
void* value_;
size_t test_size_;
+ size_t insecure_test_size_;
ssize_t signed_test_size_;
};
@@ -213,6 +228,47 @@ TEST_F(OutOfMemoryDeathTest, Calloc) {
}, kOomRegex);
}
+// OS X has no 2Gb allocation limit.
+// See https://crbug.com/169327.
+#if !defined(OS_MACOSX)
+TEST_F(OutOfMemoryDeathTest, SecurityNew) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = operator new(insecure_test_size_);
+ }, kOomRegex);
+}
+
+TEST_F(OutOfMemoryDeathTest, SecurityNewArray) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = new char[insecure_test_size_];
+ }, kOomRegex);
+}
+
+TEST_F(OutOfMemoryDeathTest, SecurityMalloc) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = malloc(insecure_test_size_);
+ }, kOomRegex);
+}
+
+TEST_F(OutOfMemoryDeathTest, SecurityRealloc) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = realloc(NULL, insecure_test_size_);
+ }, kOomRegex);
+}
+
+TEST_F(OutOfMemoryDeathTest, SecurityCalloc) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = calloc(1024, insecure_test_size_ / 1024L);
+ }, kOomRegex);
+}
+#endif // !defined(OS_MACOSX)
+
+#if defined(OS_LINUX)
+
TEST_F(OutOfMemoryDeathTest, Valloc) {
ASSERT_DEATH({
SetUpInDeathAssert();
@@ -220,7 +276,12 @@ TEST_F(OutOfMemoryDeathTest, Valloc) {
}, kOomRegex);
}
-#if defined(OS_LINUX)
+TEST_F(OutOfMemoryDeathTest, SecurityValloc) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = valloc(insecure_test_size_);
+ }, kOomRegex);
+}
#if PVALLOC_AVAILABLE == 1
TEST_F(OutOfMemoryDeathTest, Pvalloc) {
@@ -229,6 +290,13 @@ TEST_F(OutOfMemoryDeathTest, Pvalloc) {
value_ = pvalloc(test_size_);
}, kOomRegex);
}
+
+TEST_F(OutOfMemoryDeathTest, SecurityPvalloc) {
+ ASSERT_DEATH({
+ SetUpInDeathAssert();
+ value_ = pvalloc(insecure_test_size_);
+ }, kOomRegex);
+}
#endif // PVALLOC_AVAILABLE == 1
TEST_F(OutOfMemoryDeathTest, Memalign) {
@@ -415,5 +483,5 @@ TEST_F(OutOfMemoryHandledTest, UncheckedCalloc) {
EXPECT_TRUE(value_ == NULL);
}
#endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
-#endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) &&
- // !defined(ADDRESS_SANITIZER)
+#endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !(defined(OS_WIN) &&
+ // !defined(ALLOCATOR_SHIM)) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)