| 1 | // Check that __asan_poison_memory_region and ASAN_OPTIONS=poison_history_size work for partial granules. |
| 2 | // |
| 3 | // RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 20 2>&1 | FileCheck %s |
| 4 | // |
| 5 | // Partial granule |
| 6 | // RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 2>&1 | FileCheck %s |
| 7 | |
| 8 | // TODO |
| 9 | // REQUIRES: linux |
| 10 | // UNSUPPORTED: android |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | |
| 15 | extern "C" void __asan_poison_memory_region(void *, size_t); |
| 16 | extern "C" void __asan_unpoison_memory_region(void *, size_t); |
| 17 | |
| 18 | void honey_ive_poisoned_the_memory(char *x) { |
| 19 | __asan_poison_memory_region(x + 10, 20); |
| 20 | } |
| 21 | |
| 22 | void foo(char *x) { honey_ive_poisoned_the_memory(x); } |
| 23 | |
| 24 | int main(int argc, char **argv) { |
| 25 | char *x = new char[64]; |
| 26 | x[10] = 0; |
| 27 | foo(x); |
| 28 | // Bytes [0, 9]: addressable |
| 29 | // Bytes [10, 31]: poisoned by A |
| 30 | // Bytes [32, 63]: addressable |
| 31 | |
| 32 | int res = x[argc * 10]; // BOOOM |
| 33 | // CHECK: ERROR: AddressSanitizer: use-after-poison |
| 34 | // CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-2]] |
| 35 | |
| 36 | // CHECK: Memory was manually poisoned by thread T0: |
| 37 | // CHECK: honey_ive_poisoned_the_memory{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-18]] |
| 38 | // CHECK: foo{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-16]] |
| 39 | // CHECK: main{{.*}}use-after-poison-history-size-partial-granule.cpp:[[@LINE-12]] |
| 40 | |
| 41 | delete[] x; |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |