diff options
author | Yury Gribov <y.gribov@samsung.com> | 2015-12-01 09:22:41 +0000 |
---|---|---|
committer | Yury Gribov <y.gribov@samsung.com> | 2015-12-01 09:22:41 +0000 |
commit | 627fd48e2b24f1356347de58c922cce6fe7ed3e1 (patch) | |
tree | d8351d0ced1344ab6f09fd7b5fa546e6c38ad7a9 /test | |
parent | 0c487bca5d972e4d58765f453d2f3c255d63164f (diff) |
[asan] Correctly release memory allocated during early startup.
Calloc interceptor initially allocates memory from temp buffer (to serve dlsyms called during asan_init). There is a chance that some non-instrumented library (or executable) has allocated memory with calloc before asan_init and got pointer from the same temporary buffer which later caused problems with free.
Inspired by https://github.com/google/sanitizers/issues/626
Differential Revision: http://reviews.llvm.org/D14979
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254395 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/asan/TestCases/Linux/calloc-preload.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/asan/TestCases/Linux/calloc-preload.c b/test/asan/TestCases/Linux/calloc-preload.c new file mode 100644 index 000000000..eb1c6738b --- /dev/null +++ b/test/asan/TestCases/Linux/calloc-preload.c @@ -0,0 +1,36 @@ +// Test that initially callocked memory is properly freed +// (see https://github.com/google/sanitizers/issues/626). +// +// RUN: %clang %s -o %t +// RUN: env LD_PRELOAD=%shared_libasan %run %t +// +// REQUIRES: asan-dynamic-runtime +// +// This way of setting LD_PRELOAD does not work with Android test runner. +// REQUIRES: not-android + +#include <stdio.h> +#include <stdlib.h> + +static void *ptr; + +// This constructor will run before __asan_init +// so calloc will allocate memory from special pool. +static void init() { + ptr = calloc(10, 1); +} + +__attribute__((section(".preinit_array"), used)) +void *dummy = init; + +void free_memory() { + // This used to abort because + // Asan's free didn't recognize ptr. + free(ptr); +} + +int main() { + free_memory(); + return 0; +} + |