diff options
5 files changed, 118 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Windows/aligned_mallocs.cc b/compiler-rt/test/asan/TestCases/Windows/aligned_mallocs.cc new file mode 100644 index 00000000000..bbbc423c7ba --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/aligned_mallocs.cc @@ -0,0 +1,29 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// RUN: %run %t + +#include <windows.h> + +#define CHECK_ALIGNED(ptr,alignment) \ + do { \ + if (((uintptr_t)(ptr) % (alignment)) != 0) \ + return __LINE__; \ + } \ + while(0) + +int main(void) { + int *p = (int*)_aligned_malloc(1024 * sizeof(int), 32); + CHECK_ALIGNED(p, 32); + p[512] = 0; + _aligned_free(p); + + p = (int*)_aligned_malloc(128, 128); + CHECK_ALIGNED(p, 128); + p = (int*)_aligned_realloc(p, 2048 * sizeof(int), 128); + CHECK_ALIGNED(p, 128); + p[1024] = 0; + if (_aligned_msize(p, 128, 0) != 2048 * sizeof(int)) + return __LINE__; + _aligned_free(p); + + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/bitfield.cc b/compiler-rt/test/asan/TestCases/Windows/bitfield.cc new file mode 100644 index 00000000000..e1a3fc854c9 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/bitfield.cc @@ -0,0 +1,21 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// RUN: %run %t + +#include <windows.h> + +typedef struct _S { + unsigned int bf1:1; + unsigned int bf2:2; + unsigned int bf3:3; + unsigned int bf4:4; +} S; + +int main(void) { + S *s = (S*)malloc(sizeof(S)); + s->bf1 = 1; + s->bf2 = 2; + s->bf3 = 3; + s->bf4 = 4; + free(s); + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/bitfield_uaf.cc b/compiler-rt/test/asan/TestCases/Windows/bitfield_uaf.cc new file mode 100644 index 00000000000..2e63956586d --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/bitfield_uaf.cc @@ -0,0 +1,35 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// FIXME: 'cat' is needed due to PR19744. +// RUN: not %run %t 2>&1 | cat | FileCheck %s + +#include <windows.h> + +typedef struct _S { + unsigned int bf1:1; + unsigned int bf2:2; + unsigned int bf3:3; + unsigned int bf4:4; +} S; + +void make_access(S *s) { + s->bf2 = 2; +// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] +// CHECK: READ of size {{[124]}} at [[ADDR]] +// CHECK: {{#0 .* make_access .*bitfield_uaf.cc}}:[[@LINE-3]] +// CHECK: {{#1 .* main}} +} + +int main(void) { + S *s = (S*)malloc(sizeof(S)); + free(s); +// CHECK: [[ADDR]] is located 0 bytes inside of 4-byte region +// CHECK-LABEL: freed by thread T0 here: +// CHECK: {{#0 .* free }} +// CHECK: {{#1 .* main .*bitfield_uaf.cc}}:[[@LINE-4]] +// CHECK-LABEL: previously allocated by thread T0 here: +// CHECK: {{#0 .* malloc }} +// CHECK: {{#1 .* main .*bitfield_uaf.cc}}:[[@LINE-8]] + make_access(s); + return 0; +} + diff --git a/compiler-rt/test/asan/TestCases/Windows/global_const_string.cc b/compiler-rt/test/asan/TestCases/Windows/global_const_string.cc new file mode 100644 index 00000000000..6d17b245a20 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/global_const_string.cc @@ -0,0 +1,12 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// RUN: %run %t | FileCheck %s + +#include <windows.h> +#include <stdio.h> + +int main(void) { + static const char *foo = "foobarspam"; + printf("Global string is `%s`\n", foo); +// CHECK: Global string is `foobarspam` + return 0; +} diff --git a/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cc b/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cc new file mode 100644 index 00000000000..ade39fea5d5 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cc @@ -0,0 +1,21 @@ +// RUN: %clangxx_asan -O0 %s -Fe%t +// FIXME: 'cat' is needed due to PR19744. +// RUN: not %run %t 2>&1 | cat | FileCheck %s + +#include <windows.h> +#include <stdio.h> + +extern "C" const char *foo = "foobarspam"; + +int main(void) { + if (foo[16]) + printf("Boo\n"); +// CHECK-NOT: Boo +// CHECK: AddressSanitizer: global-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] +// CHECK: READ of size 1 at [[ADDR]] thread T0 +// CHECK-NEXT: {{#0 .* main .*global_const_string_oob.cc:}}[[@LINE-5]] +// CHECK: [[ADDR]] is located 5 bytes to the right of global variable [[STR:.*]] from {{'.*global_const_string_oob.cc' .*}} of size 11 +// CHECK: [[STR]] is ascii string 'foobarspam' + return 0; +} + |

