[compiler-rt] r208889 - [ASan/Win tests] Add more DLL tests: malloc & friends

Timur Iskhodzhanov timurrrr at google.com
Thu May 15 07:42:42 PDT 2014


Author: timurrrr
Date: Thu May 15 09:42:41 2014
New Revision: 208889

URL: http://llvm.org/viewvc/llvm-project?rev=208889&view=rev
Log:
[ASan/Win tests] Add more DLL tests: malloc & friends

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_aligned_mallocs.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_allocators_sanity.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
      - copied, changed from r208884, compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc
Removed:
    compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_aligned_mallocs.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_aligned_mallocs.cc?rev=208889&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_aligned_mallocs.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_aligned_mallocs.cc Thu May 15 09:42:41 2014
@@ -0,0 +1,34 @@
+// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %run %t %t.dll | FileCheck %s
+
+#include <malloc.h>
+#include <stdio.h>
+
+#define CHECK_ALIGNED(ptr,alignment) \
+  do { \
+    if (((uintptr_t)(ptr) % (alignment)) != 0) \
+      return __LINE__; \
+    } \
+  while(0)
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  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);
+
+  printf("All ok\n");
+// CHECK: All ok
+  return 0;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_allocators_sanity.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_allocators_sanity.cc?rev=208889&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_allocators_sanity.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_allocators_sanity.cc Thu May 15 09:42:41 2014
@@ -0,0 +1,39 @@
+// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %run %t %t.dll | FileCheck %s
+
+#include <malloc.h>
+#include <stdio.h>
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  int *p = (int*)malloc(1024 * sizeof(int));
+  p[512] = 0;
+  free(p);
+
+  p = (int*)malloc(128);
+  p = (int*)realloc(p, 2048 * sizeof(int));
+  p[1024] = 0;
+  free(p);
+
+  p = (int*)calloc(16, sizeof(int));
+  if (p[8] != 0)
+    return 1;
+  p[15]++;
+  if (16 * sizeof(int) != _msize(p))
+    return 2;
+  free(p);
+
+  p = new int;
+  *p = 42;
+  delete p;
+
+  p = new int[42];
+  p[15]++;
+  delete [] p;
+
+  printf("All ok\n");
+// CHECK: All ok
+
+  return 0;
+}

Copied: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc (from r208884, compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc?p2=compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc&p1=compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc&r1=208884&r2=208889&rev=208889&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob.cc Thu May 15 09:42:41 2014
@@ -10,12 +10,12 @@ int test_function() {
   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:   test_function {{.*}}dll_malloc_left_oob.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:   test_function {{.*}}dll_malloc_left_oob.cc:[[@LINE-9]]
 // CHECK:   main {{.*}}dll_host.cc
 // CHECK-LABEL: SUMMARY
   free(buffer);

Removed: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc?rev=208888&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_left_oob_crash.cc (removed)
@@ -1,23 +0,0 @@
-// 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;
-}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc?rev=208889&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_malloc_uaf.cc Thu May 15 09:42:41 2014
@@ -0,0 +1,27 @@
+// 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);
+  free(buffer);
+  buffer[0] = 42;
+// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK:   test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-3]]
+// CHECK:   main {{.*}}dll_host
+// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
+// CHECK-LABEL: freed by thread T0 here:
+// CHECK:   free
+// CHECK:   test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-9]]
+// CHECK:   main {{.*}}dll_host
+// CHECK-LABEL: previously allocated by thread T0 here:
+// CHECK:   malloc
+// CHECK:   test_function {{.*}}dll_malloc_uaf.cc:[[@LINE-14]]
+// CHECK:   main {{.*}}dll_host
+  return 0;
+}





More information about the llvm-commits mailing list