forked from OSchip/llvm-project
parent
23fe95904c
commit
3bd2c2fe90
|
@ -0,0 +1,37 @@
|
|||
// This is a host program for DLL tests.
|
||||
//
|
||||
// Just make sure we can compile this.
|
||||
// The actual compile&run sequence is to be done by the DLL tests.
|
||||
// RUN: %clangxx_asan -O0 %s -Fe%t
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s [client].dll\n", argv[0]);
|
||||
return 101;
|
||||
}
|
||||
|
||||
const char *dll_name = argv[1];
|
||||
|
||||
HMODULE h = LoadLibrary(dll_name);
|
||||
if (!h) {
|
||||
printf("Could not load DLL: %s (code: %lu)!\n",
|
||||
dll_name, GetLastError());
|
||||
return 102;
|
||||
}
|
||||
|
||||
typedef int (*test_function)();
|
||||
test_function gf = (test_function)GetProcAddress(h, "test_function");
|
||||
if (!gf) {
|
||||
printf("Could not locate test_function in the DLL!\n");
|
||||
FreeLibrary(h);
|
||||
return 103;
|
||||
}
|
||||
|
||||
int ret = gf();
|
||||
|
||||
FreeLibrary(h);
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
|
||||
// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
|
||||
// FIXME: 'cat' is needed due to PR19744.
|
||||
// RUN: not %run %t %t.dll 2>&1 | cat | FileCheck %s
|
||||
|
||||
#include <malloc.h>
|
||||
extern "C" __declspec(dllexport)
|
||||
int test_function() {
|
||||
char *buffer = (char*)malloc(42);
|
||||
buffer[-1] = 42;
|
||||
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
|
||||
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
|
||||
// CHECK: test_function {{.*}}dll_malloc_left_oob_crash.cc:[[@LINE-3]]
|
||||
// CHECK: main {{.*}}dll_host.cc
|
||||
// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region
|
||||
// CHECK-LABEL: allocated by thread T0 here:
|
||||
// CHECK: malloc
|
||||
// CHECK: test_function {{.*}}dll_malloc_left_oob_crash.cc:[[@LINE-9]]
|
||||
// CHECK: main {{.*}}dll_host.cc
|
||||
// CHECK-LABEL: SUMMARY
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue