[compiler-rt] r208871 - [ASan/Win tests] Add tests for operator new/new[]/delete/delete[]

Timur Iskhodzhanov timurrrr at google.com
Thu May 15 04:55:40 PDT 2014


Author: timurrrr
Date: Thu May 15 06:55:40 2014
New Revision: 208871

URL: http://llvm.org/viewvc/llvm-project?rev=208871&view=rev
Log:
[ASan/Win tests] Add tests for operator new/new[]/delete/delete[]

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_right_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_uaf.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_left_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_right_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_uaf.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_left_oob.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,18 @@
+// 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>
+
+int main() {
+  char *buffer = new char[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:   {{#0 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new}}[]
+// CHECK:   {{#1 .* main .*operator_array_new_left_oob.cc}}:[[@LINE-8]]
+  delete [] buffer;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_right_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_right_oob.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_right_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_right_oob.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,18 @@
+// 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>
+
+int main() {
+  char *buffer = new char[42];
+  buffer[42] = 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 .*operator_array_new_right_oob.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 0 bytes to the right of 42-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new}}[]
+// CHECK:   {{#1 .* main .*operator_array_new_right_oob.cc}}:[[@LINE-8]]
+  delete [] buffer;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_uaf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_uaf.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_uaf.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_array_new_uaf.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,23 @@
+// 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>
+
+int main() {
+  char *buffer = new char[42];
+  delete [] 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:   {{#0 .* main .*operator_array_new_uaf.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 0 bytes inside of 42-byte region
+// CHECK-LABEL: freed by thread T0 here:
+// CHECK:   {{#0 .* operator delete}}[]
+// CHECK:   {{#1 .* main .*operator_array_new_uaf.cc}}:[[@LINE-8]]
+// CHECK-LABEL: previously allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new}}[]
+// CHECK:   {{#1 .* main .*operator_array_new_uaf.cc}}:[[@LINE-12]]
+  return 0;
+}
+

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,13 @@
+// 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>
+
+int main() {
+  int *x = new int[42];
+  delete (x + 1);
+// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed
+// CHECK:   {{#0 0x.* operator delete }}
+// CHECK:   {{#1 .* main .*operator_delete_wrong_argument.cc}}:[[@LINE-3]]
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_left_oob.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_left_oob.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,18 @@
+// 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>
+
+int main() {
+  char *buffer = new char;
+  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:   {{#0 .* main .*operator_new_left_oob.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 1 bytes to the left of 1-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new }}
+// CHECK:   {{#1 .* main .*operator_new_left_oob.cc}}:[[@LINE-8]]
+  delete buffer;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_right_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_right_oob.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_right_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_right_oob.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,18 @@
+// 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>
+
+int main() {
+  char *buffer = new char;
+  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:   {{#0 .* main .*operator_new_right_oob.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 0 bytes to the right of 1-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new }}
+// CHECK:   {{#1 .* main .*operator_new_right_oob.cc}}:[[@LINE-8]]
+  delete buffer;
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_uaf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_uaf.cc?rev=208871&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_uaf.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/operator_new_uaf.cc Thu May 15 06:55:40 2014
@@ -0,0 +1,23 @@
+// 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>
+
+int main() {
+  char *buffer = new char;
+  delete buffer;
+  *buffer = 42;
+// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK:   {{#0 .* main .*operator_new_uaf.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 0 bytes inside of 1-byte region
+// CHECK-LABEL: freed by thread T0 here:
+// CHECK:   {{#0 .* operator delete }}
+// CHECK:   {{#1 .* main .*operator_new_uaf.cc}}:[[@LINE-8]]
+// CHECK-LABEL: previously allocated by thread T0 here:
+// CHECK:   {{#0 .* operator new }}
+// CHECK:   {{#1 .* main .*operator_new_uaf.cc}}:[[@LINE-12]]
+  return 0;
+}
+





More information about the llvm-commits mailing list