| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_TRUE(LogContains(kAttemptingDoubleFree)); | 187 EXPECT_TRUE(LogContains(kAttemptingDoubleFree)); |
| 188 EXPECT_TRUE(LogContains("previously allocated here")); | 188 EXPECT_TRUE(LogContains("previously allocated here")); |
| 189 EXPECT_TRUE(LogContains("freed here")); | 189 EXPECT_TRUE(LogContains("freed here")); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(AsanRtlTest, AsanCheckWildAccess) { | 192 TEST_F(AsanRtlTest, AsanCheckWildAccess) { |
| 193 FARPROC check_access_fn = | 193 FARPROC check_access_fn = |
| 194 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); | 194 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); |
| 195 ASSERT_TRUE(check_access_fn != NULL); | 195 ASSERT_TRUE(check_access_fn != NULL); |
| 196 | 196 |
| 197 #ifndef _WIN64 |
| 198 void* addr = reinterpret_cast<void*>(0x80000000); |
| 199 #else |
| 200 void* addr = reinterpret_cast<void*>(1ULL << 63); |
| 201 #endif |
| 202 |
| 197 MemoryAccessorTester tester; | 203 MemoryAccessorTester tester; |
| 198 tester.AssertMemoryErrorIsDetected( | 204 tester.AssertMemoryErrorIsDetected( |
| 199 check_access_fn, reinterpret_cast<void*>(0x80000000), WILD_ACCESS); | 205 check_access_fn, addr, WILD_ACCESS); |
| 200 EXPECT_TRUE(LogContains(kWildAccess)); | 206 EXPECT_TRUE(LogContains(kWildAccess)); |
| 201 } | 207 } |
| 202 | 208 |
| 203 #ifndef _WIN64 | 209 #ifndef _WIN64 |
| 204 // It is not possible to test the near-nullptr access with heap corruption | 210 // It is not possible to test the near-nullptr access with heap corruption |
| 205 // execution path since it depends on the unhandled exception filter which is | 211 // execution path since it depends on the unhandled exception filter which is |
| 206 // not installed in the rtl library. | 212 // not installed in the rtl library. |
| 207 TEST_F(AsanRtlTest, AsanIgnoreInvalidAccess) { | 213 TEST_F(AsanRtlTest, AsanIgnoreInvalidAccess) { |
| 208 FARPROC check_access_fn = | 214 FARPROC check_access_fn = |
| 209 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); | 215 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); |
| 210 ASSERT_TRUE(check_access_fn != NULL); | 216 ASSERT_TRUE(check_access_fn != NULL); |
| 211 | 217 |
| 212 // A near-nullptr access should not be reported by SyzyASAN. | 218 // A near-nullptr access should not be reported by SyzyASAN. |
| 213 MemoryAccessorTester tester; | 219 MemoryAccessorTester tester; |
| 214 tester.CheckAccessAndCompareContexts(check_access_fn, nullptr); | 220 tester.CheckAccessAndCompareContexts(check_access_fn, nullptr); |
| 215 EXPECT_FALSE(LogContains(kInvalidAddress)); | 221 EXPECT_FALSE(LogContains(kInvalidAddress)); |
| 216 } | 222 } |
| 217 #endif | 223 #endif |
| 218 | 224 |
| 219 TEST_F(AsanRtlTest, AsanReportInvalidAccess) { | 225 TEST_F(AsanRtlTest, AsanReportInvalidAccess) { |
| 220 FARPROC check_access_fn = | 226 FARPROC check_access_fn = |
| 221 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); | 227 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); |
| 222 ASSERT_NE(static_cast<FARPROC>(nullptr), check_access_fn); | 228 ASSERT_NE(static_cast<FARPROC>(nullptr), check_access_fn); |
| 223 | 229 |
| 224 MemoryAccessorTester tester; | 230 MemoryAccessorTester tester; |
| 225 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); | 231 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); |
| 226 ASSERT_NE(reinterpret_cast<agent::asan::AsanRuntime*>(NULL), runtime); | 232 ASSERT_NE(static_cast<agent::asan::AsanRuntime*>(nullptr), runtime); |
| 227 runtime->params().report_invalid_accesses = true; | 233 runtime->params().report_invalid_accesses = true; |
| 228 tester.AssertMemoryErrorIsDetected( | 234 tester.AssertMemoryErrorIsDetected( |
| 229 check_access_fn, reinterpret_cast<void*>(0x00000000), INVALID_ADDRESS); | 235 check_access_fn, static_cast<void*>(nullptr), INVALID_ADDRESS); |
| 230 EXPECT_TRUE(LogContains(kInvalidAddress)); | 236 EXPECT_TRUE(LogContains(kInvalidAddress)); |
| 231 } | 237 } |
| 232 | 238 |
| 233 TEST_F(AsanRtlTest, AsanCheckCorruptBlock) { | 239 TEST_F(AsanRtlTest, AsanCheckCorruptBlock) { |
| 234 void* mem = HeapAllocFunction(heap_, 0, kAllocSize); | 240 void* mem = HeapAllocFunction(heap_, 0, kAllocSize); |
| 235 reinterpret_cast<uint8_t*>(mem)[-1]--; | 241 reinterpret_cast<uint8_t*>(mem)[-1]--; |
| 236 MemoryAccessorTester tester; | 242 MemoryAccessorTester tester; |
| 237 tester.set_expected_error_type(CORRUPT_BLOCK); | 243 tester.set_expected_error_type(CORRUPT_BLOCK); |
| 238 EXPECT_TRUE(HeapFreeFunction(heap_, 0, mem)); | 244 EXPECT_TRUE(HeapFreeFunction(heap_, 0, mem)); |
| 239 EXPECT_TRUE(tester.memory_error_detected()); | 245 EXPECT_TRUE(tester.memory_error_detected()); |
| 240 EXPECT_TRUE(LogContains(kHeapCorruptBlock)); | 246 EXPECT_TRUE(LogContains(kHeapCorruptBlock)); |
| 241 EXPECT_TRUE(LogContains("previously allocated here")); | 247 EXPECT_TRUE(LogContains("previously allocated here")); |
| 242 } | 248 } |
| 243 | 249 |
| 244 TEST_F(AsanRtlTest, AsanCheckCorruptHeap) { | 250 TEST_F(AsanRtlTest, AsanCheckCorruptHeap) { |
| 245 FARPROC check_access_fn = | 251 FARPROC check_access_fn = |
| 246 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); | 252 ::GetProcAddress(asan_rtl_, "asan_check_4_byte_read_access"); |
| 247 ASSERT_TRUE(check_access_fn != NULL); | 253 ASSERT_TRUE(check_access_fn != nullptr); |
| 248 | 254 |
| 249 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); | 255 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); |
| 250 ASSERT_NE(reinterpret_cast<agent::asan::AsanRuntime*>(NULL), runtime); | 256 ASSERT_NE(reinterpret_cast<agent::asan::AsanRuntime*>(NULL), runtime); |
| 251 runtime->params().check_heap_on_failure = true; | 257 runtime->params().check_heap_on_failure = true; |
| 252 | 258 |
| 253 ScopedAsanAlloc<uint8_t> mem(this, kAllocSize); | 259 ScopedAsanAlloc<uint8_t> mem(this, kAllocSize); |
| 254 ASSERT_TRUE(mem.get() != NULL); | 260 ASSERT_TRUE(mem.get() != NULL); |
| 255 | 261 |
| 256 const size_t kMaxIterations = 10; | 262 const size_t kMaxIterations = 10; |
| 257 | 263 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // An error should be triggered when we free this block. | 303 // An error should be triggered when we free this block. |
| 298 tester.set_memory_error_detected(false); | 304 tester.set_memory_error_detected(false); |
| 299 tester.set_expected_error_type(CORRUPT_BLOCK); | 305 tester.set_expected_error_type(CORRUPT_BLOCK); |
| 300 mem.reset(NULL); | 306 mem.reset(NULL); |
| 301 EXPECT_TRUE(tester.memory_error_detected()); | 307 EXPECT_TRUE(tester.memory_error_detected()); |
| 302 | 308 |
| 303 break; | 309 break; |
| 304 } | 310 } |
| 305 } | 311 } |
| 306 | 312 |
| 313 #ifndef _WIN64 |
| 307 TEST_F(AsanRtlTest, AsanSingleSpecial1byteInstructionCheckGoodAccess) { | 314 TEST_F(AsanRtlTest, AsanSingleSpecial1byteInstructionCheckGoodAccess) { |
| 308 static const char* function_names[] = { | 315 static const char* function_names[] = { |
| 309 "asan_check_1_byte_movs_access", | 316 "asan_check_1_byte_movs_access", |
| 310 "asan_check_1_byte_cmps_access", | 317 "asan_check_1_byte_cmps_access", |
| 311 "asan_check_1_byte_stos_access" | 318 "asan_check_1_byte_stos_access" |
| 312 }; | 319 }; |
| 313 | 320 |
| 314 // Allocate memory space. | 321 // Allocate memory space. |
| 315 AllocMemoryBuffers(kAllocSize, sizeof(uint8_t)); | 322 AllocMemoryBuffers(kAllocSize, sizeof(uint8_t)); |
| 316 uint8_t* src = reinterpret_cast<uint8_t*>(memory_src_); | 323 uint8_t* src = reinterpret_cast<uint8_t*>(memory_src_); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 630 |
| 624 TEST_F(AsanRtlTest, AllocationFilterFlag) { | 631 TEST_F(AsanRtlTest, AllocationFilterFlag) { |
| 625 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); | 632 agent::asan::AsanRuntime* runtime = GetActiveRuntimeFunction(); |
| 626 SetAllocationFilterFlagFunction(); | 633 SetAllocationFilterFlagFunction(); |
| 627 EXPECT_TRUE(runtime->allocation_filter_flag()); | 634 EXPECT_TRUE(runtime->allocation_filter_flag()); |
| 628 ClearAllocationFilterFlagFunction(); | 635 ClearAllocationFilterFlagFunction(); |
| 629 EXPECT_FALSE(runtime->allocation_filter_flag()); | 636 EXPECT_FALSE(runtime->allocation_filter_flag()); |
| 630 SetAllocationFilterFlagFunction(); | 637 SetAllocationFilterFlagFunction(); |
| 631 EXPECT_TRUE(runtime->allocation_filter_flag()); | 638 EXPECT_TRUE(runtime->allocation_filter_flag()); |
| 632 } | 639 } |
| 640 #endif |
| 633 | 641 |
| 634 namespace { | 642 namespace { |
| 635 | 643 |
| 636 using ExperimentMap = std::map<std::string, std::string>; | 644 using ExperimentMap = std::map<std::string, std::string>; |
| 637 | 645 |
| 638 ExperimentMap* experiment_map = nullptr; | 646 ExperimentMap* experiment_map = nullptr; |
| 639 | 647 |
| 640 static void WINAPI | 648 static void WINAPI |
| 641 ExperimentCallback(const char* feature_name, const char* feature_state) { | 649 ExperimentCallback(const char* feature_name, const char* feature_state) { |
| 642 ASSERT_TRUE(experiment_map != nullptr); | 650 ASSERT_TRUE(experiment_map != nullptr); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 665 EXPECT_EQ("Enabled", experiments["SyzyASANLargeBlockHeap"]); | 673 EXPECT_EQ("Enabled", experiments["SyzyASANLargeBlockHeap"]); |
| 666 EXPECT_EQ("Disabled", experiments["SyzyASANCrashpad"]); | 674 EXPECT_EQ("Disabled", experiments["SyzyASANCrashpad"]); |
| 667 | 675 |
| 668 // This implicitly asserts the full contents of the map by asserting | 676 // This implicitly asserts the full contents of the map by asserting |
| 669 // on the size after looking up the expected keys. | 677 // on the size after looking up the expected keys. |
| 670 EXPECT_EQ(3U, experiments.size()); | 678 EXPECT_EQ(3U, experiments.size()); |
| 671 } | 679 } |
| 672 | 680 |
| 673 } // namespace asan | 681 } // namespace asan |
| 674 } // namespace agent | 682 } // namespace agent |
| OLD | NEW |