35 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 <stdio.h>6#include <string.h>7 8void call_memcpy(void* (*f)(void *, const void *, size_t),9 void *a, const void *b, size_t c) {10 f(a, b, c);11}12 13extern "C" __declspec(dllexport)14int test_function() {15 char buff1[6] = "Hello", buff2[5];16 17 call_memcpy(&memcpy, buff2, buff1, 5);18 if (buff1[2] != buff2[2])19 return 2;20 printf("Initial test OK\n");21 fflush(0);22// CHECK: Initial test OK23 24 call_memcpy(&memcpy, buff2, buff1, 6);25// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]26// CHECK: WRITE of size 6 at [[ADDR]] thread T027// CHECK-NEXT: mem{{.*}}28// CHECK-NEXT: call_memcpy29// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy_indirect.cpp:[[@LINE-5]]30// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame31// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy_indirect.cpp32// CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable33 return 0;34}35