1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
2// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
3// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
4
5// On windows 64-bit, the memchr function is written in assembly and is not
6// hookable with the interception library. There is not enough padding before
7// the function and there is a short jump on the second instruction which
8// doesn't not allow enough space to encode a 64-bit indirect jump.
9// UNSUPPORTED: x86_64-windows
10
11#include <string.h>
12
13extern "C" __declspec(dllexport)
14int test_function() {
15 char buff[6] = "Hello";
16
17 memchr(s: buff, c: 'z', n: 7);
18// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
19// CHECK: READ of size 7 at [[ADDR]] thread T0
20// CHECK-NEXT: memchr
21// CHECK-NEXT: memchr
22// CHECK-NEXT: test_function {{.*}}dll_intercept_memchr.cpp:[[@LINE-5]]
23// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
24// CHECK-NEXT: test_function {{.*}}dll_intercept_memchr.cpp
25// CHECK: 'buff'{{.*}} <== Memory access at offset {{.*}} overflows this variable
26 return 0;
27}
28

source code of compiler-rt/test/asan/TestCases/Windows/dll_intercept_memchr.cpp