forked from OSchip/llvm-project
[ASan/Win tests] Add tests for stack array manipulation, as well as a use-after-return test
llvm-svn: 208873
This commit is contained in:
parent
01124a0132
commit
a357badc58
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue