[compiler-rt] r208873 - [ASan/Win tests] Add tests for stack array manipulation, as well as a use-after-return test

Timur Iskhodzhanov timurrrr at google.com
Thu May 15 05:09:46 PDT 2014


Author: timurrrr
Date: Thu May 15 07:09:45 2014
New Revision: 208873

URL: http://llvm.org/viewvc/llvm-project?rev=208873&view=rev
Log:
[ASan/Win tests] Add tests for stack array manipulation, as well as a use-after-return test

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_left_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_right_oob.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_sanity.cc
    compiler-rt/trunk/test/asan/TestCases/Windows/stack_use_after_return.cc

Added: compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_left_oob.cc?rev=208873&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_left_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_left_oob.cc Thu May 15 07:09:45 2014
@@ -0,0 +1,17 @@
+// 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>
+
+int main() {
+  int subscript = -1;
+  char buffer[42];
+  buffer[subscript] = 42;
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK-NEXT: {{#0 .* main .*stack_array_left_oob.cc}}:[[@LINE-3]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: {{#0 .* main .*stack_array_left_oob.cc}}
+// CHECK: 'buffer' <== Memory access at offset [[OFFSET]] underflows this variable
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_right_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_right_oob.cc?rev=208873&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_right_oob.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_right_oob.cc Thu May 15 07:09:45 2014
@@ -0,0 +1,17 @@
+// 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>
+
+int main() {
+  int subscript = 42;
+  char buffer[42];
+  buffer[subscript] = 42;
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK-NEXT: {{#0 .* main .*stack_array_right_oob.cc}}:[[@LINE-3]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: {{#0 .* main .*stack_array_right_oob.cc}}
+// CHECK: 'buffer' <== Memory access at offset [[OFFSET]] overflows this variable
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_sanity.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_sanity.cc?rev=208873&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_sanity.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/stack_array_sanity.cc Thu May 15 07:09:45 2014
@@ -0,0 +1,12 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t | FileCheck %s
+
+#include <stdio.h>
+
+int main() {
+  int subscript = 1;
+  char buffer[42];
+  buffer[subscript] = 42;
+  printf("OK\n");
+// CHECK: OK
+}

Added: compiler-rt/trunk/test/asan/TestCases/Windows/stack_use_after_return.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/stack_use_after_return.cc?rev=208873&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/stack_use_after_return.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/stack_use_after_return.cc Thu May 15 07:09:45 2014
@@ -0,0 +1,23 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t 2>&1 | cat | FileCheck %s
+
+char *x;
+
+void foo() {
+  char stack_buffer[42];
+  x = &stack_buffer[13];
+}
+
+int main() {
+  foo();
+  *x = 42;
+// CHECK: AddressSanitizer: stack-use-after-return
+// CHECK: WRITE of size 1 at {{.*}} thread T0
+// CHECK-NEXT: {{#0 0x.* in main .*stack_use_after_return.cc}}:[[@LINE-3]]
+//
+// CHECK: is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
+// CHECK-NEXT: {{#0 0x.* in foo .*stack_use_after_return.cc}}
+//
+// CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] is inside this variable
+}





More information about the llvm-commits mailing list