brintos

brintos / llvm-project-archived public Read only

0
0
Text · 968 B · ae23f86 Raw
29 lines · cpp
1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t2// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll3// RUN: not %run %t %t.dll 2>&1 | FileCheck %s4 5#include <malloc.h>6 7extern "C" __declspec(dllexport)8int test_function() {9  int *buffer = (int*)malloc(42);10  free(buffer);11  buffer[0] = 42;12  // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]13  // CHECK: WRITE of size 4 at [[ADDR]] thread T014  // CHECK-NEXT:  test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-3]]15  // CHECK-NEXT:  main {{.*}}dll_host16  //17  // CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region18  // CHECK-LABEL: freed by thread T0 here:19  // CHECK-NEXT:  free20  // CHECK:  test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-10]]21  // CHECK-NEXT:  main {{.*}}dll_host22  //23  // CHECK-LABEL: previously allocated by thread T0 here:24  // CHECK-NEXT:  malloc25  // CHECK:  test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-16]]26  // CHECK-NEXT:  main {{.*}}dll_host27  return 0;28}29