summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
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/sanitizer_common/sanitizer_allocator.h
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/sanitizer_common/sanitizer_allocator.h')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.h2
1 files changed, 2 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);
OpenPOWER on IntegriCloud