forked from OSchip/llvm-project
[ASan/Win tests] Add tests for downcast-related overflows, as well as CRT initiazliers
llvm-svn: 208865
This commit is contained in:
parent
5c44b08912
commit
dd2d84a223
|
@ -0,0 +1,31 @@
|
|||
// RUN: %clangxx_asan -O0 %s -Fe%t
|
||||
// RUN: %run %t | FileCheck %s
|
||||
|
||||
// This is a test for http://code.google.com/p/address-sanitizer/issues/detail?id=305
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef void (*FPTR)();
|
||||
|
||||
// __xi_a and __xi_z are defined in VC/crt/src/crt0dat.c
|
||||
// and are located in .CRT$XIA and .CRT$XIZ respectively.
|
||||
extern "C" FPTR __xi_a, __xi_z;
|
||||
|
||||
int main() {
|
||||
unsigned count = 0;
|
||||
|
||||
// Iterate through CRT initializers.
|
||||
for (FPTR* it = &__xi_a; it < &__xi_z; ++it) {
|
||||
if (*it)
|
||||
count++;
|
||||
}
|
||||
|
||||
printf("Number of nonzero CRT initializers: %u\n", count);
|
||||
// CHECK: Number of nonzero CRT initializers
|
||||
}
|
||||
|
||||
void call_me_maybe() {}
|
||||
|
||||
#pragma data_seg(".CRT$XIB")
|
||||
// Add an initializer that shouldn't get its own redzone.
|
||||
FPTR run_on_startup = call_me_maybe;
|
|
@ -0,0 +1,9 @@
|
|||
// RUN: %clangxx_asan -O0 %s -Fe%t
|
||||
// RUN: %run %t | FileCheck %s
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello, world!\n");
|
||||
// CHECK: Hello, world!
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// RUN: %clangxx_asan -O0 %s -Fe%t
|
||||
// FIXME: 'cat' is needed due to PR19744.
|
||||
// RUN: not %run %t 2>&1 | cat | FileCheck %s
|
||||
|
||||
class Parent {
|
||||
public:
|
||||
int field;
|
||||
};
|
||||
|
||||
class Child : public Parent {
|
||||
public:
|
||||
int extra_field;
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
Parent *p = new Parent;
|
||||
Child *c = (Child*)p; // Intentional error here!
|
||||
c->extra_field = 42;
|
||||
// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
|
||||
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
|
||||
// CHECK: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_heap.cc}}:[[@LINE-3]]
|
||||
// CHECK: [[ADDR]] is located 0 bytes to the right of 4-byte region
|
||||
// CHECK: allocated by thread T0 here:
|
||||
// CHECK: #0 {{.*}} operator new
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// RUN: %clangxx_asan -O0 %s -Fe%t
|
||||
// FIXME: 'cat' is needed due to PR19744.
|
||||
// RUN: not %run %t 2>&1 | cat | FileCheck %s
|
||||
|
||||
class Parent {
|
||||
public:
|
||||
int field;
|
||||
};
|
||||
|
||||
class Child : public Parent {
|
||||
public:
|
||||
int extra_field;
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
Parent p;
|
||||
Child *c = (Child*)&p; // Intentional error here!
|
||||
c->extra_field = 42;
|
||||
// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
|
||||
// CHECK: WRITE of size 4 at [[ADDR]] thread T0
|
||||
// CHECK-NEXT: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_stack.cc}}:[[@LINE-3]]
|
||||
// CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:[0-9]+]] in frame
|
||||
// CHECK-NEXT: {{#0 0x[0-9a-f]* in main }}
|
||||
// CHECK: 'p' <== Memory access at offset [[OFFSET]] overflows this variable
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue