45 lines · cpp
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 %s4//5// Partial granule6// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=poison_history_size=1000 not %run %t 2>&1 | FileCheck %s7 8// TODO9// REQUIRES: linux10// UNSUPPORTED: android11 12#include <stdio.h>13#include <stdlib.h>14 15extern "C" void __asan_poison_memory_region(void *, size_t);16extern "C" void __asan_unpoison_memory_region(void *, size_t);17 18void honey_ive_poisoned_the_memory(char *x) {19 __asan_poison_memory_region(x + 10, 20);20}21 22void foo(char *x) { honey_ive_poisoned_the_memory(x); }23 24int main(int argc, char **argv) {25 char *x = new char[64];26 x[10] = 0;27 foo(x);28 // Bytes [0, 9]: addressable29 // Bytes [10, 31]: poisoned by A30 // Bytes [32, 63]: addressable31 32 int res = x[argc * 10]; // BOOOM33 // CHECK: ERROR: AddressSanitizer: use-after-poison34 // 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