| 69 | } |
| 70 | |
| 71 | TEST(StackGuardTest, CanaryGuardTestOverflow) { |
| 72 | const auto& guard = GetGuard<TCanaryGuard>(); |
| 73 | |
| 74 | char *rawPtr, *alignedPtr = nullptr; |
| 75 | constexpr size_t sizeInPages = 4; |
| 76 | ASSERT_TRUE(GetAlignedMemory(sizeInPages + 1, rawPtr, alignedPtr)); |
| 77 | guard.Protect(alignedPtr, PageSize, false); // set previous guard |
| 78 | alignedPtr += PageSize; // leave first page for previous guard |
| 79 | guard.Protect(alignedPtr, sizeInPages * PageSize, true); |
| 80 | |
| 81 | EXPECT_TRUE(guard.CheckOverflow(alignedPtr)); |
| 82 | EXPECT_TRUE(guard.CheckOverride(alignedPtr, sizeInPages * PageSize)); |
| 83 | |
| 84 | // Overwrite previous guard |
| 85 | *(alignedPtr - 1) = 42; |
| 86 | |
| 87 | EXPECT_FALSE(guard.CheckOverflow(alignedPtr)); |
| 88 | |
| 89 | free(rawPtr); |
| 90 | } |
| 91 | |
| 92 | TEST(StackGuardTest, CanaryGuardTestOverride) { |
| 93 | const auto& guard = GetGuard<TCanaryGuard>(); |
nothing calls this directly
no test coverage detected