[sanitizer] Fix boundary condition in LargeMmapAllocator::GetBlockBegin. Patch by Sergey Matveev

llvm-svn: 179007
This commit is contained in:
Kostya Serebryany 2013-04-08 08:43:22 +00:00
parent 85c19f5a73
commit e6459977b8
2 changed files with 9 additions and 2 deletions

View File

@ -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);
}

View File

@ -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<Allocator32Compact>();
}
TEST(SanitizerCommon, LargeMmapAllocatorIteration) {
LargeMmapAllocator<> a;
a.Init();