brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 11011e4 Raw
28 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s5// REQUIRES: stable-runtime6 7// Test use-after-free report in the case when access is at the right border of8// the allocation.9 10#include <stdlib.h>11int main() {12  volatile char *x = (char*)malloc(sizeof(char));13  free((void*)x);14  *x = 42;15  // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}16  // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}17  // CHECK: {{WRITE of size 1 at 0x.* thread T0}}18  // CHECK: {{    #0 0x.* in main .*use-after-free-right.cpp:}}[[@LINE-4]]19  // CHECK: {{0x.* is located 0 bytes inside of 1-byte region .0x.*,0x.*}}20  // CHECK: {{freed by thread T0 here:}}21  // CHECK: {{    #0 0x.* in .*free}}22  // CHECK: {{    #[1-3] 0x.* in main .*use-after-free-right.cpp:}}[[@LINE-9]]23 24  // CHECK: {{previously allocated by thread T0 here:}}25  // CHECK: {{    #0 0x.* in .*malloc}}26  // CHECK: {{    #[1-3] 0x.* in main .*use-after-free-right.cpp:}}[[@LINE-14]]27}28