Skip to content

Commit 0f9a777

Browse files
committed
Fixup and enable tests.
Enable a bunch of tests that were previously broken in one or the other runtime configuration. Fix tests that were looking for particular frame numbers, these moved around because the new interception methods added a few new frames to the stack.
1 parent 37a2cc9 commit 0f9a777

36 files changed

+168
-279
lines changed

compiler-rt/test/asan/TestCases/Windows/bitfield_uaf.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ void make_access(S *s) {
2121
int main(void) {
2222
S *s = (S*)malloc(sizeof(S));
2323
free(s);
24-
// CHECK: [[ADDR]] is located 0 bytes inside of 4-byte region
25-
// CHECK-LABEL: freed by thread T0 here:
26-
// CHECK: {{#0 .* free }}
27-
// CHECK: {{#1 .* main .*bitfield_uaf.cpp}}:[[@LINE-4]]
28-
// CHECK-LABEL: previously allocated by thread T0 here:
29-
// CHECK: {{#0 .* malloc }}
30-
// CHECK: {{#1 .* main .*bitfield_uaf.cpp}}:[[@LINE-8]]
24+
// CHECK: [[ADDR]] is located 0 bytes inside of 4-byte region
25+
// CHECK-LABEL: freed by thread T0 here:
26+
// CHECK: {{#0 .* free }}
27+
// CHECK: {{ .* main .*bitfield_uaf.cpp}}:[[@LINE-4]]
28+
// CHECK-LABEL: previously allocated by thread T0 here:
29+
// CHECK: {{#0 .* malloc }}
30+
// CHECK: {{.* main .*bitfield_uaf.cpp}}:[[@LINE-8]]
3131
make_access(s);
3232
return 0;
3333
}

compiler-rt/test/asan/TestCases/Windows/calloc_left_oob.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
int main() {
77
int *buffer = (int*)calloc(42, sizeof(int));
88
buffer[-1] = 42;
9-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10-
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
11-
// CHECK-NEXT: {{#0 .* main .*calloc_left_oob.cpp}}:[[@LINE-3]]
12-
// CHECK: [[ADDR]] is located 4 bytes before 168-byte region
13-
// CHECK: allocated by thread T0 here:
14-
// CHECK-NEXT: {{#0 .* calloc }}
15-
// CHECK-NEXT: {{#1 .* main .*calloc_left_oob.cpp}}:[[@LINE-8]]
9+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10+
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
11+
// CHECK-NEXT: {{#0 .* main .*calloc_left_oob.cpp}}:[[@LINE-3]]
12+
// CHECK: [[ADDR]] is located 4 bytes before 168-byte region
13+
// CHECK: allocated by thread T0 here:
14+
// CHECK: {{#0 .* calloc }}
15+
// CHECK: {{.* main .*calloc_left_oob.cpp}}:[[@LINE-8]]
1616
free(buffer);
1717
}

compiler-rt/test/asan/TestCases/Windows/calloc_right_oob.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
int main() {
77
int *buffer = (int*)calloc(42, sizeof(int));
88
buffer[42] = 42;
9-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10-
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
11-
// CHECK-NEXT: {{#0 .* main .*calloc_right_oob.cpp}}:[[@LINE-3]]
12-
// CHECK: [[ADDR]] is located 0 bytes after 168-byte region
13-
// CHECK: allocated by thread T0 here:
14-
// CHECK-NEXT: {{#0 .* calloc }}
15-
// CHECK-NEXT: {{#1 .* main .*calloc_right_oob.cpp}}:[[@LINE-8]]
9+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10+
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
11+
// CHECK-NEXT: {{#0 .* main .*calloc_right_oob.cpp}}:[[@LINE-3]]
12+
// CHECK: [[ADDR]] is located 0 bytes after 168-byte region
13+
// CHECK: allocated by thread T0 here:
14+
// CHECK-NEXT: {{#0 .* calloc }}
15+
// CHECK: {{ .* main .*calloc_right_oob.cpp}}:[[@LINE-8]]
1616
free(buffer);
1717
}

compiler-rt/test/asan/TestCases/Windows/calloc_uaf.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ int main() {
77
int *buffer = (int*)calloc(42, sizeof(int));
88
free(buffer);
99
buffer[0] = 42;
10-
// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
11-
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
12-
// CHECK-NEXT: {{#0 .* main .*calloc_uaf.cpp}}:[[@LINE-3]]
13-
// CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region
14-
// CHECK: freed by thread T0 here:
15-
// CHECK-NEXT: {{#0 .* free }}
16-
// CHECK-NEXT: {{#1 .* main .*calloc_uaf.cpp}}:[[@LINE-8]]
17-
// CHECK: previously allocated by thread T0 here:
18-
// CHECK-NEXT: {{#0 .* calloc }}
19-
// CHECK-NEXT: {{#1 .* main .*calloc_uaf.cpp}}:[[@LINE-12]]
10+
// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
11+
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
12+
// CHECK-NEXT: {{#0 .* main .*calloc_uaf.cpp}}:[[@LINE-3]]
13+
// CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region
14+
// CHECK: freed by thread T0 here:
15+
// CHECK-NEXT: {{#0 .* free }}
16+
// CHECK: {{.* main .*calloc_uaf.cpp}}:[[@LINE-8]]
17+
// CHECK: previously allocated by thread T0 here:
18+
// CHECK-NEXT: {{#0 .* calloc }}
19+
// CHECK: {{.* main .*calloc_uaf.cpp}}:[[@LINE-12]]
2020
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cl_asan -Od %s -Fe%t /link /WX
2+
// RUN: %clang_cl_asan -Od %s -Fe%t /link /WX /INFERASANLIBS:DEBUG
3+
4+
// Link with /WX under each configuration to ensure there are
5+
// no warnings (ex: defaultlib mismatch, pragma detect mismatch)
6+
// when linking.
7+
8+
int main() { return 0; }

compiler-rt/test/asan/TestCases/Windows/dll_heap_allocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cl %LD %s %Fe%t.dll -DHEAP_LIBRARY %MD \
22
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t.lib %}
3-
// RUN: %clang_cl %s %t.lib %Fe%t -fsanitize=address %MT
3+
// RUN: %clang_cl_asan %s %t.lib %Fe%t
44
// RUN: %run %t 2>&1 | FileCheck %s
55

66
// Check that ASan does not fail when releasing allocations that occurred within

compiler-rt/test/asan/TestCases/Windows/dll_host.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,6 @@
55
// Just make sure we can compile this.
66
// The actual compile&run sequence is to be done by the DLL tests.
77
// RUN: %clang_cl_asan -Od %s -Fe%t
8-
//
9-
// Get the list of ASan wrappers exported by the main module RTL:
10-
// note: The mangling decoration (i.e. @4 )is removed because calling convention
11-
// differ from 32-bit and 64-bit.
12-
// RUN: dumpbin /EXPORTS %t | grep -o "__asan_wrap[^ ]*" | sed -e s/@.*// > %t.exports1
13-
//
14-
// The exception handlers differ in 32-bit and 64-bit, so we ignore them:
15-
// RUN: grep '[E]XPORT:' %s | sed -e 's/.*[E]XPORT: //' > %t.exports2
16-
// EXPORT: __asan_wrap__except_handler3
17-
// EXPORT: __asan_wrap__except_handler4
18-
// EXPORT: __asan_wrap___C_specific_handler
19-
//
20-
// Get the list of ASan wrappers imported by the DLL RTL:
21-
// [BEWARE: be really careful with the sed commands, as this test can be run
22-
// from different environments with different shells and seds]
23-
// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cpp \
24-
// RUN: | grep -v define | sed -e s/.*(/__asan_wrap_/ -e s/).*// \
25-
// RUN: > %t.imports1
26-
//
27-
// Add functions interecepted in asan_malloc.win.cpp and asan_win.cpp.
28-
// RUN: grep '[I]MPORT:' %s | sed -e 's/.*[I]MPORT: //' > %t.imports2
29-
// IMPORT: __asan_wrap_HeapAlloc
30-
// IMPORT: __asan_wrap_HeapFree
31-
// IMPORT: __asan_wrap_HeapReAlloc
32-
// IMPORT: __asan_wrap_HeapSize
33-
// IMPORT: __asan_wrap_CreateThread
34-
// IMPORT: __asan_wrap_RaiseException
35-
// IMPORT: __asan_wrap_RtlRaiseException
36-
// IMPORT: __asan_wrap_SetUnhandledExceptionFilter
37-
// IMPORT: __asan_wrap_RtlSizeHeap
38-
// IMPORT: __asan_wrap_RtlAllocateHeap
39-
// IMPORT: __asan_wrap_RtlReAllocateHeap
40-
// IMPORT: __asan_wrap_RtlFreeHeap
41-
//
42-
// RUN: cat %t.imports1 %t.imports2 | sort | uniq > %t.imports-sorted
43-
// RUN: cat %t.exports1 %t.exports2 | sort | uniq > %t.exports-sorted
44-
//
45-
// Now make sure the DLL thunk imports everything:
46-
// RUN: echo
47-
// RUN: echo "=== NOTE === If you see a mismatch below, please update asan_win_dll_thunk.cpp"
48-
// RUN: diff %t.imports-sorted %t.exports-sorted
49-
// REQUIRES: asan-static-runtime
508

519
#include <stdio.h>
5210
#include <windows.h>

compiler-rt/test/asan/TestCases/Windows/dll_malloc_left_oob.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ extern "C" __declspec(dllexport)
77
int test_function() {
88
char *buffer = (char*)malloc(42);
99
buffer[-1] = 42;
10-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
11-
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
12-
// CHECK-NEXT: test_function {{.*}}dll_malloc_left_oob.cpp:[[@LINE-3]]
13-
// CHECK-NEXT: main {{.*}}dll_host.cpp
14-
//
15-
// CHECK: [[ADDR]] is located 1 bytes before 42-byte region
16-
// CHECK-LABEL: allocated by thread T0 here:
17-
// CHECK-NEXT: malloc
18-
// CHECK-NEXT: test_function {{.*}}dll_malloc_left_oob.cpp:[[@LINE-10]]
19-
// CHECK-NEXT: main {{.*}}dll_host.cpp
20-
// CHECK-LABEL: SUMMARY
10+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
11+
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
12+
// CHECK-NEXT: test_function {{.*}}dll_malloc_left_oob.cpp:[[@LINE-3]]
13+
// CHECK-NEXT: main {{.*}}dll_host.cpp
14+
//
15+
// CHECK: [[ADDR]] is located 1 bytes before 42-byte region
16+
// CHECK-LABEL: allocated by thread T0 here:
17+
// CHECK-NEXT: malloc
18+
// CHECK: test_function {{.*}}dll_malloc_left_oob.cpp:[[@LINE-10]]
19+
// CHECK-NEXT: main {{.*}}dll_host.cpp
20+
// CHECK-LABEL: SUMMARY
2121
free(buffer);
2222
return 0;
2323
}

compiler-rt/test/asan/TestCases/Windows/dll_malloc_uaf.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ int test_function() {
99
int *buffer = (int*)malloc(42);
1010
free(buffer);
1111
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 T0
14-
// CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-3]]
15-
// CHECK-NEXT: main {{.*}}dll_host
16-
//
17-
// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
18-
// CHECK-LABEL: freed by thread T0 here:
19-
// CHECK-NEXT: free
20-
// CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-10]]
21-
// CHECK-NEXT: main {{.*}}dll_host
22-
//
23-
// CHECK-LABEL: previously allocated by thread T0 here:
24-
// CHECK-NEXT: malloc
25-
// CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-16]]
26-
// CHECK-NEXT: main {{.*}}dll_host
12+
// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
13+
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
14+
// CHECK-NEXT: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-3]]
15+
// CHECK-NEXT: main {{.*}}dll_host
16+
//
17+
// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
18+
// CHECK-LABEL: freed by thread T0 here:
19+
// CHECK-NEXT: free
20+
// CHECK: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-10]]
21+
// CHECK-NEXT: main {{.*}}dll_host
22+
//
23+
// CHECK-LABEL: previously allocated by thread T0 here:
24+
// CHECK-NEXT: malloc
25+
// CHECK: test_function {{.*}}dll_malloc_uaf.cpp:[[@LINE-16]]
26+
// CHECK-NEXT: main {{.*}}dll_host
2727
return 0;
2828
}

compiler-rt/test/asan/TestCases/Windows/double_free.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ int main() {
77
int *x = (int*)malloc(42 * sizeof(int));
88
free(x);
99
free(x);
10-
// CHECK: AddressSanitizer: attempting double-free on [[ADDR:0x[0-9a-f]+]]
11-
// CHECK-NEXT: {{#0 .* free }}
12-
// CHECK-NEXT: {{#1 .* main .*double_free.cpp}}:[[@LINE-3]]
13-
// CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region
14-
// CHECK-LABEL: freed by thread T0 here:
15-
// CHECK-NEXT: {{#0 .* free }}
16-
// CHECK-NEXT: {{#1 .* main .*double_free.cpp}}:[[@LINE-8]]
17-
// CHECK-LABEL: previously allocated by thread T0 here:
18-
// CHECK-NEXT: {{#0 .* malloc }}
19-
// CHECK-NEXT: {{#1 .* main .*double_free.cpp}}:[[@LINE-12]]
10+
// CHECK: AddressSanitizer: attempting double-free on [[ADDR:0x[0-9a-f]+]]
11+
// CHECK-NEXT: {{#0 .* free }}
12+
// CHECK: {{.* main .*double_free.cpp}}:[[@LINE-3]]
13+
// CHECK: [[ADDR]] is located 0 bytes inside of 168-byte region
14+
// CHECK-LABEL: freed by thread T0 here:
15+
// CHECK-NEXT: {{#0 .* free }}
16+
// CHECK: {{.* main .*double_free.cpp}}:[[@LINE-8]]
17+
// CHECK-LABEL: previously allocated by thread T0 here:
18+
// CHECK-NEXT: {{#0 .* malloc }}
19+
// CHECK: {{.* main .*double_free.cpp}}:[[@LINE-12]]
2020
return 0;
2121
}

compiler-rt/test/asan/TestCases/Windows/free_hook_realloc.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
// FIXME: merge this with the common free_hook_realloc test when we can run
66
// common tests on Windows.
77

8-
// FIXME: Doesn't work with DLLs
9-
// XFAIL: win32-dynamic-asan
10-
118
#include <stdlib.h>
129
#include <io.h>
1310
#include <sanitizer/allocator_interface.h>

compiler-rt/test/asan/TestCases/Windows/intercept_strdup.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ int main() {
1515

1616
subscript = -1;
1717
ptr[subscript] = 42;
18-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
19-
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
20-
// CHECK: {{#0 .* main .*}}intercept_strdup.cpp:[[@LINE-3]]
21-
// CHECK: [[ADDR]] is located 1 bytes before 6-byte region
22-
// CHECK: allocated by thread T0 here:
23-
//
24-
// The first frame is our wrapper normally but will be malloc in the dynamic
25-
// config.
26-
// CHECK: #0 {{.*}} in {{malloc|strdup}}
27-
//
28-
// The local call to _strdup above may be the second or third frame depending
29-
// on whether we're using the dynamic config.
30-
// CHECK: #{{[12]}} {{.*}} in main {{.*}}intercept_strdup.cpp:[[@LINE-21]]
18+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
19+
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
20+
// CHECK: {{#0 .* main .*}}intercept_strdup.cpp:[[@LINE-3]]
21+
// CHECK: [[ADDR]] is located 1 bytes before 6-byte region
22+
// CHECK: allocated by thread T0 here:
23+
//
24+
// The first frame is our wrapper normally but will be malloc in the dynamic
25+
// config.
26+
// CHECK: #0 {{.*}} in {{malloc|_strdup}}
27+
//
28+
// The local call to _strdup above may be the second or third frame depending
29+
// on whether we're using the dynamic config.
30+
// CHECK: #{{[12]}} {{.*}} in main {{.*}}intercept_strdup.cpp:[[@LINE-21]]
3131
free(ptr);
3232
}

compiler-rt/test/asan/TestCases/Windows/interface_symbols_windows.cpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

compiler-rt/test/asan/TestCases/Windows/malloc_left_oob.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
int main() {
77
char *buffer = (char*)malloc(42);
88
buffer[-1] = 42;
9-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10-
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
11-
// CHECK-NEXT: {{#0 .* main .*malloc_left_oob.cpp}}:[[@LINE-3]]
12-
// CHECK: [[ADDR]] is located 1 bytes before 42-byte region
13-
// CHECK: allocated by thread T0 here:
14-
// CHECK-NEXT: {{#0 .* malloc }}
15-
// CHECK-NEXT: {{#1 .* main .*malloc_left_oob.cpp}}:[[@LINE-8]]
9+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10+
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
11+
// CHECK-NEXT: {{#0 .* main .*malloc_left_oob.cpp}}:[[@LINE-3]]
12+
// CHECK: [[ADDR]] is located 1 bytes before 42-byte region
13+
// CHECK: allocated by thread T0 here:
14+
// CHECK-NEXT: {{#0 .* malloc }}
15+
// CHECK: {{ .* main .*malloc_left_oob.cpp}}:[[@LINE-8]]
1616
free(buffer);
1717
}

compiler-rt/test/asan/TestCases/Windows/malloc_right_oob.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
int main() {
77
char *buffer = (char*)malloc(42);
88
buffer[42] = 42;
9-
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10-
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
11-
// CHECK-NEXT: {{#0 .* main .*malloc_right_oob.cpp}}:[[@LINE-3]]
12-
// CHECK: [[ADDR]] is located 0 bytes after 42-byte region
13-
// CHECK: allocated by thread T0 here:
14-
// CHECK-NEXT: {{#0 .* malloc }}
15-
// CHECK-NEXT: {{#1 .* main .*malloc_right_oob.cpp}}:[[@LINE-8]]
9+
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
10+
// CHECK: WRITE of size 1 at [[ADDR]] thread T0
11+
// CHECK-NEXT: {{#0 .* main .*malloc_right_oob.cpp}}:[[@LINE-3]]
12+
// CHECK: [[ADDR]] is located 0 bytes after 42-byte region
13+
// CHECK: allocated by thread T0 here:
14+
// CHECK-NEXT: {{#0 .* malloc }}
15+
// CHECK: {{ .* main .*malloc_right_oob.cpp}}:[[@LINE-8]]
1616
free(buffer);
1717
}

0 commit comments

Comments
 (0)