[llvm-commits] [compiler-rt] r172717 - in /compiler-rt/trunk/lib/asan: asan_allocator2.cc tests/asan_noinst_test.cc
Alexey Samsonov
samsonov at google.com
Thu Jan 17 05:25:18 PST 2013
Author: samsonov
Date: Thu Jan 17 07:25:17 2013
New Revision: 172717
URL: http://llvm.org/viewvc/llvm-project?rev=172717&view=rev
Log:
[ASan] fix __asan_get_ownership(p) and __asan_get_allocated_size(p) for the p = malloc(0)
Modified:
compiler-rt/trunk/lib/asan/asan_allocator2.cc
compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=172717&r1=172716&r2=172717&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Thu Jan 17 07:25:17 2013
@@ -675,16 +675,18 @@
}
bool __asan_get_ownership(const void *p) {
- return AllocationSize(reinterpret_cast<uptr>(p)) > 0;
+ uptr ptr = reinterpret_cast<uptr>(p);
+ return (ptr == kReturnOnZeroMalloc) || (AllocationSize(ptr) > 0);
}
uptr __asan_get_allocated_size(const void *p) {
if (p == 0) return 0;
- uptr allocated_size = AllocationSize(reinterpret_cast<uptr>(p));
+ uptr ptr = reinterpret_cast<uptr>(p);
+ uptr allocated_size = AllocationSize(ptr);
// Die if p is not malloced or if it is already freed.
- if (allocated_size == 0) {
+ if (allocated_size == 0 && ptr != kReturnOnZeroMalloc) {
GET_STACK_TRACE_FATAL_HERE;
- ReportAsanGetAllocatedSizeNotOwned(reinterpret_cast<uptr>(p), &stack);
+ ReportAsanGetAllocatedSizeNotOwned(ptr, &stack);
}
return allocated_size;
}
Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=172717&r1=172716&r2=172717&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Thu Jan 17 07:25:17 2013
@@ -382,8 +382,16 @@
free(array);
EXPECT_FALSE(__asan_get_ownership(array));
EXPECT_DEATH(__asan_get_allocated_size(array), kGetAllocatedSizeErrorMsg);
-
delete int_ptr;
+
+ void *zero_alloc = Ident(malloc(0));
+ if (zero_alloc != 0) {
+ // If malloc(0) is not null, this pointer is owned and should have valid
+ // allocated size.
+ EXPECT_TRUE(__asan_get_ownership(zero_alloc));
+ EXPECT_EQ(0U, __asan_get_allocated_size(zero_alloc));
+ }
+ free(zero_alloc);
}
TEST(AddressSanitizerInterface, GetCurrentAllocatedBytesTest) {
More information about the llvm-commits
mailing list