summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorTimur Iskhodzhanov <timurrrr@google.com>2014-05-15 16:02:56 +0000
committerTimur Iskhodzhanov <timurrrr@google.com>2014-05-15 16:02:56 +0000
commitbd6cee7cc34dfa351ea0a023a1fef165299a089f (patch)
tree11d7cd7de31a3978f87ee6a598af0fe0b7d7e493 /compiler-rt
parent6262d2349c024e53679be6f2995168a64e6c8221 (diff)
downloadbcm5719-llvm-bd6cee7cc34dfa351ea0a023a1fef165299a089f.tar.gz
bcm5719-llvm-bd6cee7cc34dfa351ea0a023a1fef165299a089f.zip
[ASan/Win tests] Add memcpy/strdup/strlen interception tests
llvm-svn: 208899
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/test/asan/TestCases/Windows/intercept_memcpy.cc32
-rw-r--r--compiler-rt/test/asan/TestCases/Windows/intercept_strdup.cc28
-rw-r--r--compiler-rt/test/asan/TestCases/Windows/intercept_strlen.cc28
3 files changed, 88 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Windows/intercept_memcpy.cc b/compiler-rt/test/asan/TestCases/Windows/intercept_memcpy.cc
new file mode 100644
index 00000000000..4e52b1a90e7
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Windows/intercept_memcpy.cc
@@ -0,0 +1,32 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: not %run %t 2>&1 | cat | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+void call_memcpy(void* (*f)(void *, const void *, size_t),
+ void *a, const void *b, size_t c) {
+ f(a, b, c);
+}
+
+int main() {
+ char buff1[6] = "Hello", buff2[5];
+
+ call_memcpy(&memcpy, buff2, buff1, 5);
+ if (buff1[2] != buff2[2])
+ return 2;
+ printf("Initial test OK\n");
+ fflush(0);
+// CHECK: Initial test OK
+
+ call_memcpy(&memcpy, buff2, buff1, 6);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 6 at [[ADDR]] thread T0
+// CHECK: __asan_memcpy
+// CHECK-NEXT: call_memcpy
+// CHECK: main {{.*}}intercept_memcpy.cc:[[@LINE-5]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
+// CHECK-NEXT: #0 {{.*}} main
+// CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable
+}
diff --git a/compiler-rt/test/asan/TestCases/Windows/intercept_strdup.cc b/compiler-rt/test/asan/TestCases/Windows/intercept_strdup.cc
new file mode 100644
index 00000000000..1e1a26d6a77
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Windows/intercept_strdup.cc
@@ -0,0 +1,28 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: not %run %t 2>&1 | cat | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+
+int main() {
+ char *ptr = _strdup("Hello");
+ int subscript = 1;
+ ptr[subscript] = '3';
+ printf("%s\n", ptr);
+ fflush(0);
+// CHECK: H3llo
+
+ subscript = -1;
+ ptr[subscript] = 42;
+// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK: {{#0 .* main .*}}intercept_strdup.cc:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 1 bytes to the left of 6-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK: {{#0 .* malloc }}
+// CHECK: {{#1 .* _strdup }}
+// CHECK: {{#2 .* main .*}}intercept_strdup.cc:[[@LINE-16]]
+ free(ptr);
+}
diff --git a/compiler-rt/test/asan/TestCases/Windows/intercept_strlen.cc b/compiler-rt/test/asan/TestCases/Windows/intercept_strlen.cc
new file mode 100644
index 00000000000..f32f4033515
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Windows/intercept_strlen.cc
@@ -0,0 +1,28 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: not %run %t 2>&1 | cat | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+int main() {
+ char str[] = "Hello";
+ if (5 != strlen(str))
+ return 1;
+
+ printf("Initial test OK\n");
+ fflush(0);
+// CHECK: Initial test OK
+
+ str[5] = '!'; // Losing '\0' at the end.
+ int len = strlen(str);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// FIXME: Should be READ of size 1, see issue 155.
+// CHECK: READ of size {{[0-9]+}} at [[ADDR]] thread T0
+// CHECK: strlen
+// CHECK-NEXT: main {{.*}}intercept_strlen.cc:[[@LINE-5]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
+// CHECK-NEXT: main {{.*}}intercept_strlen.cc
+// CHECK: 'str' <== Memory access at offset {{.*}} overflows this variable
+ return len < 6;
+}
OpenPOWER on IntegriCloud