diff options
| -rw-r--r-- | compiler-rt/lib/asan/asan_fake_stack.cc | 6 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/lit_tests/TestCases/stack-use-after-return.cc | 22 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/tests/asan_noinst_test.cc | 9 |
3 files changed, 26 insertions, 11 deletions
diff --git a/compiler-rt/lib/asan/asan_fake_stack.cc b/compiler-rt/lib/asan/asan_fake_stack.cc index 15409712abd..02f92c1f251 100644 --- a/compiler-rt/lib/asan/asan_fake_stack.cc +++ b/compiler-rt/lib/asan/asan_fake_stack.cc @@ -107,11 +107,11 @@ void FakeStack::AllocateOneSizeClass(uptr size_class) { // size_class, new_mem, new_mem + ClassMmapSize(size_class), // ClassMmapSize(size_class)); uptr i; - for (i = 0; i < ClassMmapSize(size_class); - i += ClassSize(size_class)) { + uptr size = ClassSize(size_class); + for (i = 0; i + size <= ClassMmapSize(size_class); i += size) { size_classes_[size_class].FifoPush((FakeFrame*)(new_mem + i)); } - CHECK(i == ClassMmapSize(size_class)); + CHECK_LE(i, ClassMmapSize(size_class)); allocated_size_classes_[size_class] = new_mem; } diff --git a/compiler-rt/lib/asan/lit_tests/TestCases/stack-use-after-return.cc b/compiler-rt/lib/asan/lit_tests/TestCases/stack-use-after-return.cc index 8064ffd8c95..750f187e766 100644 --- a/compiler-rt/lib/asan/lit_tests/TestCases/stack-use-after-return.cc +++ b/compiler-rt/lib/asan/lit_tests/TestCases/stack-use-after-return.cc @@ -1,15 +1,21 @@ -// XFAIL: * // RUN: %clangxx_asan -fsanitize=use-after-return -O0 %s -o %t && \ -// RUN: %t 2>&1 | FileCheck %s +// RUN: not %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -fsanitize=use-after-return -O1 %s -o %t && \ -// RUN: %t 2>&1 | FileCheck %s +// RUN: not %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -fsanitize=use-after-return -O2 %s -o %t && \ -// RUN: %t 2>&1 | FileCheck %s +// RUN: not %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -fsanitize=use-after-return -O3 %s -o %t && \ -// RUN: %t 2>&1 | FileCheck %s +// RUN: not %t 2>&1 | FileCheck %s +// Regression test for a CHECK failure with small stack size and large frame. +// RUN: %clangxx_asan -fsanitize=use-after-return -O3 %s -o %t -DkSize=10000 && \ +// RUN: (ulimit -s 65; not %t) 2>&1 | FileCheck %s #include <stdio.h> +#ifndef kSize +# define kSize 1 +#endif + __attribute__((noinline)) char *Ident(char *x) { fprintf(stderr, "1: %p\n", x); @@ -18,8 +24,8 @@ char *Ident(char *x) { __attribute__((noinline)) char *Func1() { - char local; - return Ident(&local); + char local[kSize]; + return Ident(local); } __attribute__((noinline)) @@ -28,7 +34,7 @@ void Func2(char *x) { *x = 1; // CHECK: WRITE of size 1 {{.*}} thread T0 // CHECK: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]] - // CHECK: is located {{.*}} in frame <{{.*}}Func1{{.*}}> of T0's stack + // CHECK: is located in stack of thread T0 at offset } int main(int argc, char **argv) { diff --git a/compiler-rt/lib/asan/tests/asan_noinst_test.cc b/compiler-rt/lib/asan/tests/asan_noinst_test.cc index cab37836244..0d681caabc4 100644 --- a/compiler-rt/lib/asan/tests/asan_noinst_test.cc +++ b/compiler-rt/lib/asan/tests/asan_noinst_test.cc @@ -793,3 +793,12 @@ TEST(AddressSanitizerInterface, CallocReturnsZeroMem) { } } } + +TEST(AddressSanitizerInterface, FakeStack) { + for (int iter = 0; iter < 1000; iter++) { + for (int size = 8; size <= (1 << 14); size += 8) { + uptr p = __asan_stack_malloc(size, 0x12345678); + CHECK(p); + } + } +} |

