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 <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 TEST(SecurityTest, TCMALLOC_TEST(MemoryAllocationRestrictionsNewArray)) { | 140 TEST(SecurityTest, TCMALLOC_TEST(MemoryAllocationRestrictionsNewArray)) { |
141 if (!IsTcMallocBypassed()) { | 141 if (!IsTcMallocBypassed()) { |
142 scoped_ptr<char[]> ptr( | 142 scoped_ptr<char[]> ptr( |
143 HideValueFromCompiler(new (nothrow) char[kTooBigAllocSize])); | 143 HideValueFromCompiler(new (nothrow) char[kTooBigAllocSize])); |
144 ASSERT_TRUE(!ptr); | 144 ASSERT_TRUE(!ptr); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 // The tests bellow check for overflows in new[] and calloc(). | 148 // The tests bellow check for overflows in new[] and calloc(). |
149 | 149 |
150 #if defined(OS_IOS) || defined(OS_WIN) | 150 #if defined(OS_IOS) || defined(OS_WIN) || defined(THREAD_SANITIZER) |
151 #define DISABLE_ON_IOS_AND_WIN(function) DISABLED_##function | 151 #define DISABLE_ON_IOS_AND_WIN_AND_TSAN(function) DISABLED_##function |
152 #else | 152 #else |
153 #define DISABLE_ON_IOS_AND_WIN(function) function | 153 #define DISABLE_ON_IOS_AND_WIN_AND_TSAN(function) function |
154 #endif | 154 #endif |
155 | 155 |
156 // There are platforms where these tests are known to fail. We would like to | 156 // There are platforms where these tests are known to fail. We would like to |
157 // be able to easily check the status on the bots, but marking tests as | 157 // be able to easily check the status on the bots, but marking tests as |
158 // FAILS_ is too clunky. | 158 // FAILS_ is too clunky. |
159 void OverflowTestsSoftExpectTrue(bool overflow_detected) { | 159 void OverflowTestsSoftExpectTrue(bool overflow_detected) { |
160 if (!overflow_detected) { | 160 if (!overflow_detected) { |
161 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_MACOSX) | 161 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_MACOSX) |
162 // Sadly, on Linux, Android, and OSX we don't have a good story yet. Don't | 162 // Sadly, on Linux, Android, and OSX we don't have a good story yet. Don't |
163 // fail the test, but report. | 163 // fail the test, but report. |
164 printf("Platform has overflow: %s\n", | 164 printf("Platform has overflow: %s\n", |
165 !overflow_detected ? "yes." : "no."); | 165 !overflow_detected ? "yes." : "no."); |
166 #else | 166 #else |
167 // Otherwise, fail the test. (Note: EXPECT are ok in subfunctions, ASSERT | 167 // Otherwise, fail the test. (Note: EXPECT are ok in subfunctions, ASSERT |
168 // aren't). | 168 // aren't). |
169 EXPECT_TRUE(overflow_detected); | 169 EXPECT_TRUE(overflow_detected); |
170 #endif | 170 #endif |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. | 174 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. |
175 // IOS doesn't honor nothrow, so disable the test there. | 175 // IOS doesn't honor nothrow, so disable the test there. |
176 // Crashes on Windows Dbg builds, disable there as well. | 176 // Crashes on Windows Dbg builds, disable there as well. |
177 TEST(SecurityTest, DISABLE_ON_IOS_AND_WIN(NewOverflow)) { | 177 TEST(SecurityTest, DISABLE_ON_IOS_AND_WIN_AND_TSAN(NewOverflow)) { |
178 const size_t kArraySize = 4096; | 178 const size_t kArraySize = 4096; |
179 // We want something "dynamic" here, so that the compiler doesn't | 179 // We want something "dynamic" here, so that the compiler doesn't |
180 // immediately reject crazy arrays. | 180 // immediately reject crazy arrays. |
181 const size_t kDynamicArraySize = HideValueFromCompiler(kArraySize); | 181 const size_t kDynamicArraySize = HideValueFromCompiler(kArraySize); |
182 // numeric_limits are still not constexpr until we switch to C++11, so we | 182 // numeric_limits are still not constexpr until we switch to C++11, so we |
183 // use an ugly cast. | 183 // use an ugly cast. |
184 const size_t kMaxSizeT = ~static_cast<size_t>(0); | 184 const size_t kMaxSizeT = ~static_cast<size_t>(0); |
185 ASSERT_EQ(numeric_limits<size_t>::max(), kMaxSizeT); | 185 ASSERT_EQ(numeric_limits<size_t>::max(), kMaxSizeT); |
186 const size_t kArraySize2 = kMaxSizeT / kArraySize + 10; | 186 const size_t kArraySize2 = kMaxSizeT / kArraySize + 10; |
187 const size_t kDynamicArraySize2 = HideValueFromCompiler(kArraySize2); | 187 const size_t kDynamicArraySize2 = HideValueFromCompiler(kArraySize2); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // kRandomMask, so we use it as an additional detection mechanism. | 294 // kRandomMask, so we use it as an additional detection mechanism. |
295 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 295 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
296 bool impossible_random_address = | 296 bool impossible_random_address = |
297 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 297 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
298 EXPECT_FALSE(impossible_random_address); | 298 EXPECT_FALSE(impossible_random_address); |
299 } | 299 } |
300 | 300 |
301 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) | 301 #endif // (defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(__x86_64__) |
302 | 302 |
303 } // namespace | 303 } // namespace |
OLD | NEW |