[sanitizer] Fix boundary condition in LargeMmapAllocator::GetBlockBegin. Patch by...
authorKostya Serebryany <kcc@google.com>
Mon, 8 Apr 2013 08:43:22 +0000 (08:43 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 8 Apr 2013 08:43:22 +0000 (08:43 +0000)
llvm-svn: 179007

compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc

index d45762f..d0716a4 100644 (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);
   }
index a8747a5..895ca01 100644 (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();