[compiler-rt] r208899 - [ASan/Win tests] Add memcpy/strdup/strlen interception tests

Timur Iskhodzhanov timurrrr at google.com
Thu May 15 09:02:56 PDT 2014


Author: timurrrr
Date: Thu May 15 11:02:56 2014
New Revision: 208899

URL: http://llvm.org/viewvc/llvm-project?rev=208899&view=rev
Log:
[ASan/Win tests] Add memcpy/strdup/strlen interception tests

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/intercept_memcpy.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strlen.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/intercept_memcpy.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/intercept_memcpy.cc?rev=208899&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/intercept_memcpy.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/intercept_memcpy.cc Thu May 15 11:02:56 2014
@@ -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
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc?rev=208899&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc Thu May 15 11:02:56 2014
@@ -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);
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strlen.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strlen.cc?rev=208899&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strlen.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strlen.cc Thu May 15 11:02:56 2014
@@ -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;
+}





More information about the llvm-commits mailing list