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(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX
) | 90 #if defined(OS_IOS) || defined(OS_WIN) || defined(OS_LINUX) |
91 #define MAYBE_NewOverflow DISABLED_NewOverflow | 91 #define MAYBE_NewOverflow DISABLED_NewOverflow |
92 #else | 92 #else |
93 #define MAYBE_NewOverflow NewOverflow | 93 #define MAYBE_NewOverflow NewOverflow |
94 #endif | 94 #endif |
95 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. | 95 // Test array[TooBig][X] and array[X][TooBig] allocations for int overflows. |
96 // IOS doesn't honor nothrow, so disable the test there. | 96 // IOS doesn't honor nothrow, so disable the test there. |
97 // Crashes on Windows Dbg builds, disable there as well. | 97 // Crashes on Windows Dbg builds, disable there as well. |
98 // Fails on Mac 10.8 http://crbug.com/227092 | |
99 // Disabled on Linux because failing Linux Valgrind bot, and Valgrind exclusions | 98 // Disabled on Linux because failing Linux Valgrind bot, and Valgrind exclusions |
100 // are not currently read. See http://crbug.com/582398 | 99 // are not currently read. See http://crbug.com/582398 |
101 TEST(SecurityTest, MAYBE_NewOverflow) { | 100 TEST(SecurityTest, MAYBE_NewOverflow) { |
102 const size_t kArraySize = 4096; | 101 const size_t kArraySize = 4096; |
103 // We want something "dynamic" here, so that the compiler doesn't | 102 // We want something "dynamic" here, so that the compiler doesn't |
104 // immediately reject crazy arrays. | 103 // immediately reject crazy arrays. |
105 const size_t kDynamicArraySize = HideValueFromCompiler(kArraySize); | 104 const size_t kDynamicArraySize = HideValueFromCompiler(kArraySize); |
106 // numeric_limits are still not constexpr until we switch to C++11, so we | 105 // numeric_limits are still not constexpr until we switch to C++11, so we |
107 // use an ugly cast. | 106 // use an ugly cast. |
108 const size_t kMaxSizeT = ~static_cast<size_t>(0); | 107 const size_t kMaxSizeT = ~static_cast<size_t>(0); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // kRandomMask, so we use it as an additional detection mechanism. | 178 // kRandomMask, so we use it as an additional detection mechanism. |
180 const uintptr_t kRandomMask = 0x3fffffffffffULL; | 179 const uintptr_t kRandomMask = 0x3fffffffffffULL; |
181 bool impossible_random_address = | 180 bool impossible_random_address = |
182 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; | 181 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; |
183 EXPECT_FALSE(impossible_random_address); | 182 EXPECT_FALSE(impossible_random_address); |
184 } | 183 } |
185 | 184 |
186 #endif // defined(OS_LINUX) && defined(__x86_64__) | 185 #endif // defined(OS_LINUX) && defined(__x86_64__) |
187 | 186 |
188 } // namespace | 187 } // namespace |
OLD | NEW |