| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 printf("Platform has overflow: %s\n", | 80 printf("Platform has overflow: %s\n", |
| 81 !overflow_detected ? "yes." : "no."); | 81 !overflow_detected ? "yes." : "no."); |
| 82 #else | 82 #else |
| 83 // Otherwise, fail the test. (Note: EXPECT are ok in subfunctions, ASSERT | 83 // Otherwise, fail the test. (Note: EXPECT are ok in subfunctions, ASSERT |
| 84 // aren't). | 84 // aren't). |
| 85 EXPECT_TRUE(overflow_detected); | 85 EXPECT_TRUE(overflow_detected); |
| 86 #endif | 86 #endif |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 #if defined(OS_IOS) || defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) | 90 #if defined(OS_IOS) || defined(ADDRESS_SANITIZER) || \ |
| 91 defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER) |
| 91 #define MAYBE_NewOverflow DISABLED_NewOverflow | 92 #define MAYBE_NewOverflow DISABLED_NewOverflow |
| 92 #else | 93 #else |
| 93 #define MAYBE_NewOverflow NewOverflow | 94 #define MAYBE_NewOverflow NewOverflow |
| 94 #endif | 95 #endif |
| 95 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. | 96 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. |
| 96 // IOS doesn't honor nothrow, so disable the test there. | 97 // IOS doesn't honor nothrow, so disable the test there. |
| 97 // Disabled under XSan because asan aborts when new returns nullptr, | 98 // Disabled under XSan because asan aborts when new returns nullptr, |
| 98 // https://bugs.chromium.org/p/chromium/issues/detail?id=690271#c15 | 99 // https://bugs.chromium.org/p/chromium/issues/detail?id=690271#c15 |
| 99 TEST(SecurityTest, MAYBE_NewOverflow) { | 100 TEST(SecurityTest, MAYBE_NewOverflow) { |
| 100 const size_t kArraySize = 4096; | 101 const size_t kArraySize = 4096; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // kRandomMask, so we use it as an additional detection mechanism. | 179 // kRandomMask, so we use it as an additional detection mechanism. |
| 179 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 180 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
| 180 bool impossible_random_address = | 181 bool impossible_random_address = |
| 181 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 182 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
| 182 EXPECT_FALSE(impossible_random_address); | 183 EXPECT_FALSE(impossible_random_address); |
| 183 } | 184 } |
| 184 | 185 |
| 185 #endif // defined(OS_LINUX) && defined(__x86_64__) | 186 #endif // defined(OS_LINUX) && defined(__x86_64__) |
| 186 | 187 |
| 187 } // namespace | 188 } // namespace |
| OLD | NEW |