[asan] extend overflow-in-qsort.cc to check both unwind kinds. One more test for SlowUnwind. Move both to Linux dir (no slow unwind on Mac)
llvm-svn: 170122
This commit is contained in:
parent
78ba6c1b37
commit
704c1cb23a
|
@ -1,4 +1,6 @@
|
||||||
// RUN: %clangxx_asan -O2 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
|
// RUN: %clangxx_asan -O2 %s -o %t
|
||||||
|
// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=1 %t 2>&1 | %symbolize | FileCheck %s --check-prefix=CHECK-FAST
|
||||||
|
// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=0 %t 2>&1 | %symbolize | FileCheck %s --check-prefix=CHECK-SLOW
|
||||||
|
|
||||||
// Test how well we unwind in presence of qsort in the stack
|
// Test how well we unwind in presence of qsort in the stack
|
||||||
// (i.e. if we can unwind through a function compiled w/o frame pointers).
|
// (i.e. if we can unwind through a function compiled w/o frame pointers).
|
||||||
|
@ -6,15 +8,14 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int global_array[10];
|
int *GlobalPtr;
|
||||||
volatile int one = 1;
|
|
||||||
|
|
||||||
extern "C"
|
extern "C" {
|
||||||
int QsortCallback(const void *a, const void *b) {
|
int QsortCallback(const void *a, const void *b) {
|
||||||
char *x = (char*)a;
|
char *x = (char*)a;
|
||||||
char *y = (char*)b;
|
char *y = (char*)b;
|
||||||
printf("Calling QsortCallback\n");
|
printf("Calling QsortCallback\n");
|
||||||
global_array[one * 10] = 0; // BOOM
|
GlobalPtr = new int[10];
|
||||||
return (int)*x - (int)*y;
|
return (int)*x - (int)*y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +25,16 @@ void MyQsort(char *a, size_t size) {
|
||||||
qsort(a, size, sizeof(char), QsortCallback);
|
qsort(a, size, sizeof(char), QsortCallback);
|
||||||
printf("Done\n"); // Avoid tail call.
|
printf("Done\n"); // Avoid tail call.
|
||||||
}
|
}
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char a[2] = {1, 2};
|
char a[2] = {1, 2};
|
||||||
MyQsort(a, 2);
|
MyQsort(a, 2);
|
||||||
|
return GlobalPtr[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: ERROR: AddressSanitizer: global-buffer-overflow
|
// Fast unwind: can not unwind through qsort.
|
||||||
// CHECK: #0{{.*}} in {{_?}}QsortCallback
|
// FIXME: this test does not properly work with slow unwind yet.
|
||||||
// CHECK: is located 0 bytes to the right of global variable 'global_array
|
|
||||||
|
// CHECK-FAST: ERROR: AddressSanitizer: heap-buffer-overflow
|
||||||
|
// CHECK-SLOW: ERROR: AddressSanitizer: heap-buffer-overflow
|
|
@ -0,0 +1,47 @@
|
||||||
|
// RUN: %clangxx_asan -O2 %s -o %t
|
||||||
|
// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=1 %t 2>&1 | %symbolize | FileCheck %s --check-prefix=CHECK-FAST
|
||||||
|
// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=0 %t 2>&1 | %symbolize | FileCheck %s --check-prefix=CHECK-SLOW
|
||||||
|
|
||||||
|
// Test how well we unwind in presence of qsort in the stack
|
||||||
|
// (i.e. if we can unwind through a function compiled w/o frame pointers).
|
||||||
|
// https://code.google.com/p/address-sanitizer/issues/detail?id=137
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int global_array[10];
|
||||||
|
volatile int one = 1;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
int QsortCallback(const void *a, const void *b) {
|
||||||
|
char *x = (char*)a;
|
||||||
|
char *y = (char*)b;
|
||||||
|
printf("Calling QsortCallback\n");
|
||||||
|
global_array[one * 10] = 0; // BOOM
|
||||||
|
return (int)*x - (int)*y;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((noinline))
|
||||||
|
void MyQsort(char *a, size_t size) {
|
||||||
|
printf("Calling qsort\n");
|
||||||
|
qsort(a, size, sizeof(char), QsortCallback);
|
||||||
|
printf("Done\n"); // Avoid tail call.
|
||||||
|
}
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char a[2] = {1, 2};
|
||||||
|
MyQsort(a, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fast unwind: can not unwind through qsort.
|
||||||
|
|
||||||
|
// CHECK-FAST: ERROR: AddressSanitizer: global-buffer-overflow
|
||||||
|
// CHECK-FAST: #0{{.*}} in QsortCallback
|
||||||
|
// CHECK-FAST-NOT: MyQsort
|
||||||
|
// CHECK-FAST: is located 0 bytes to the right of global variable 'global_array
|
||||||
|
|
||||||
|
// CHECK-SLOW: ERROR: AddressSanitizer: global-buffer-overflow
|
||||||
|
// CHECK-SLOW: #0{{.*}} in QsortCallback
|
||||||
|
// CHECK-SLOW: #{{.*}} in MyQsort
|
||||||
|
// CHECK-SLOW: #{{.*}} in main
|
||||||
|
// CHECK-SLOW: is located 0 bytes to the right of global variable 'global_array
|
Loading…
Reference in New Issue