diff options
author | Timur Iskhodzhanov <timurrrr@google.com> | 2013-05-20 13:05:58 +0000 |
---|---|---|
committer | Timur Iskhodzhanov <timurrrr@google.com> | 2013-05-20 13:05:58 +0000 |
commit | 41d69f4fd5454d5bf2614cbb3e8ed77a935c880b (patch) | |
tree | ef9d7a3fc193a279be4ff4020ac083dbb15a00b9 /lib/asan/tests | |
parent | e7ca05603222f61bab630f619bf59c0c927ff7de (diff) | |
download | compiler-rt-41d69f4fd5454d5bf2614cbb3e8ed77a935c880b.tar.gz compiler-rt-41d69f4fd5454d5bf2614cbb3e8ed77a935c880b.tar.bz2 compiler-rt-41d69f4fd5454d5bf2614cbb3e8ed77a935c880b.tar.xz |
Fix realloc'ing freed/invalid pointers
See https://code.google.com/p/address-sanitizer/issues/detail?id=187 for the details
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182255 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/tests')
-rw-r--r-- | lib/asan/tests/asan_test.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/asan/tests/asan_test.cc b/lib/asan/tests/asan_test.cc index a85c179e..112d81a6 100644 --- a/lib/asan/tests/asan_test.cc +++ b/lib/asan/tests/asan_test.cc @@ -353,6 +353,18 @@ TEST(AddressSanitizer, ReallocTest) { free(ptr2); } +TEST(AddressSanitizer, ReallocFreedPointerTest) { + void *ptr = Ident(malloc(42)); + ASSERT_TRUE(NULL != ptr); + free(ptr); + EXPECT_DEATH(ptr = realloc(ptr, 77), "attempting double-free"); +} + +TEST(AddressSanitizer, ReallocInvalidPointerTest) { + void *ptr = Ident(malloc(42)); + EXPECT_DEATH(ptr = realloc((int*)ptr + 1, 77), "attempting free.*not malloc"); +} + TEST(AddressSanitizer, ZeroSizeMallocTest) { // Test that malloc(0) and similar functions don't return NULL. void *ptr = Ident(malloc(0)); |