From e6459977b8f396caefc3ac0995d7e1f95adabdee Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Mon, 8 Apr 2013 08:43:22 +0000 Subject: [PATCH] [sanitizer] Fix boundary condition in LargeMmapAllocator::GetBlockBegin. Patch by Sergey Matveev llvm-svn: 179007 --- compiler-rt/lib/sanitizer_common/sanitizer_allocator.h | 2 +- .../sanitizer_common/tests/sanitizer_allocator_test.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h index d45762f0a4b6..d0716a4a1c8b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h @@ -1014,7 +1014,7 @@ class LargeMmapAllocator { CHECK_GE(nearest_chunk, h->map_beg); CHECK_LT(nearest_chunk, h->map_beg + h->map_size); CHECK_LE(nearest_chunk, p); - if (h->map_beg + h->map_size < p) + if (h->map_beg + h->map_size <= p) return 0; return GetUser(h); } 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 a8747a5d24a9..895ca01d97b2 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -337,6 +337,14 @@ TEST(SanitizerCommon, LargeMmapAllocator) { a.Deallocate(&stats, allocated[i]); } } + + // Regression test for boundary condition in GetBlockBegin(). + uptr page_size = GetPageSizeCached(); + char *p = (char *)a.Allocate(&stats, page_size, 1); + CHECK_EQ(p, a.GetBlockBegin(p)); + CHECK_EQ(p, (char *)a.GetBlockBegin(p + page_size - 1)); + CHECK_NE(p, (char *)a.GetBlockBegin(p + page_size)); + a.Deallocate(&stats, p); } template @@ -629,7 +637,6 @@ TEST(SanitizerCommon, SizeClassAllocator32Iteration) { TestSizeClassAllocatorIteration(); } - TEST(SanitizerCommon, LargeMmapAllocatorIteration) { LargeMmapAllocator<> a; a.Init();