diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-12-09 01:31:51 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2017-12-09 01:31:51 +0000 |
commit | 32e20e4417a0dd8870d8ec5c9be21f5c2d1ebc63 (patch) | |
tree | 1a5c7d5b32c2072600e208cb10157e60e22e59c9 /test/hwasan/TestCases/use-after-free.cc | |
parent | ba5a005732212e5f111094e9aec667da37417624 (diff) |
Hardware-assisted AddressSanitizer (compiler-rt)
Summary:
Runtime library for HWASan, initial commit.
Does not randomize tags yet, does not handle stack or globals.
Reviewers: kcc, pcc, alekseyshl
Subscribers: srhines, kubamracek, dberris, mgorny, llvm-commits, krytarowski
Differential Revision: https://reviews.llvm.org/D40935
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320231 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/hwasan/TestCases/use-after-free.cc')
-rw-r--r-- | test/hwasan/TestCases/use-after-free.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/hwasan/TestCases/use-after-free.cc b/test/hwasan/TestCases/use-after-free.cc new file mode 100644 index 000000000..a99cd3c0e --- /dev/null +++ b/test/hwasan/TestCases/use-after-free.cc @@ -0,0 +1,29 @@ +// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// REQUIRES: stable-runtime + +#include <stdlib.h> +#include <sanitizer/hwasan_interface.h> + +int main() { + __hwasan_enable_allocator_tagging(); + char *x = (char*)malloc(10); + free(x); + __hwasan_disable_allocator_tagging(); + return x[5]; + // CHECK: READ of size 1 at + // CHECK: #0 {{.*}} in __hwasan_load1 {{.*}}hwasan.cc + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:15 + + // CHECK: freed here: + // CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13 + + // CHECK: previously allocated here: + // CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12 + + // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in __hwasan_load1 +} |