summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-03-11 09:43:12 +0000
committerKostya Serebryany <kcc@google.com>2013-03-11 09:43:12 +0000
commit0f5c20b417c63627e12b3c503d4e9d17709682a2 (patch)
tree9a8d3e331e3ac390c9d959c5708abf90fc1cb8bf /compiler-rt/lib
parent1e02e73c30a272b0caa36537b11a4a0d2f5b0070 (diff)
downloadbcm5719-llvm-0f5c20b417c63627e12b3c503d4e9d17709682a2.tar.gz
bcm5719-llvm-0f5c20b417c63627e12b3c503d4e9d17709682a2.zip
[sanitizer] make SizeClassAllocator64::GetBlockBegin more bullet proof (by Sergey Matveev)
llvm-svn: 176799
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.h2
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc6
2 files changed, 8 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
index e1f06f3b6ae..7d4554c6638 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
@@ -358,10 +358,12 @@ class SizeClassAllocator64 {
void *GetBlockBegin(void *p) {
uptr class_id = GetSizeClass(p);
uptr size = SizeClassMap::Size(class_id);
+ if (!size) return 0;
uptr chunk_idx = GetChunkIdx((uptr)p, size);
uptr reg_beg = (uptr)p & ~(kRegionSize - 1);
uptr beg = chunk_idx * size;
uptr next_beg = beg + size;
+ if (class_id >= kNumClasses) return 0;
RegionInfo *region = GetRegionInfo(class_id);
if (region->mapped_user >= next_beg)
return reinterpret_cast<void*>(reg_beg + beg);
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
index ad1aa593e5f..0e0d9a90e48 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
@@ -115,6 +115,12 @@ void TestSizeClassAllocator() {
CHECK_EQ(last_total_allocated, total_allocated);
}
+ // Check that GetBlockBegin never crashes.
+ for (uptr x = 0, step = kAddressSpaceSize / 100000;
+ x < kAddressSpaceSize - step; x += step)
+ if (a->PointerIsMine(reinterpret_cast<void *>(x)))
+ Ident(a->GetBlockBegin(reinterpret_cast<void *>(x)));
+
a->TestOnlyUnmap();
delete a;
}
OpenPOWER on IntegriCloud