llvm-capstone/compiler-rt/test/gwp_asan/repeated_alloc.cpp
Mitch Phillips 21184ec5c4 [GWP-ASan] Integration with Scudo [5].
Summary:
See D60593 for further information.

This patch adds GWP-ASan support to the Scudo hardened allocator. It also
implements end-to-end integration tests using Scudo as the backing allocator.
The tests include crash handling for buffer over/underflow as well as
use-after-free detection.

Reviewers: vlad.tsyrklevich, cryptoad

Reviewed By: vlad.tsyrklevich, cryptoad

Subscribers: kubamracek, mgorny, #sanitizers, llvm-commits, morehouse

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D62929

llvm-svn: 363584
2019-06-17 17:45:34 +00:00

29 lines
847 B
C++

// REQUIRES: gwp_asan
// This test ensures that normal allocation/memory access/deallocation works
// as expected and we didn't accidentally break the supporting allocator.
// RUN: %clangxx_gwp_asan %s -o %t
// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=1 %run %t
// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=2 %run %t
// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=11 %run %t
// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=12 %run %t
// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=13 %run %t
#include <cstdlib>
int main() {
void* Pointers[16];
for (unsigned i = 0; i < 16; ++i) {
char *Ptr = reinterpret_cast<char*>(malloc(1 << i));
Pointers[i] = Ptr;
*Ptr = 0;
Ptr[(1 << i) - 1] = 0;
}
for (unsigned i = 0; i < 16; ++i) {
free(Pointers[i]);
}
return 0;
}