asan: fix out-of-bounds access in quarantine
authorDmitry Vyukov <dvyukov@google.com>
Thu, 14 Apr 2016 09:52:33 +0000 (09:52 +0000)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 14 Apr 2016 09:52:33 +0000 (09:52 +0000)
llvm-svn: 266288

compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h

index 9e0bf2d..095c806 100644 (file)
@@ -101,10 +101,12 @@ class Quarantine {
   void NOINLINE DoRecycle(Cache *c, Callback cb) {
     while (QuarantineBatch *b = c->DequeueBatch()) {
       const uptr kPrefetch = 16;
+      COMPILER_CHECK(kPrefetch <= ARRAY_SIZE(b->batch));
       for (uptr i = 0; i < kPrefetch; i++)
         PREFETCH(b->batch[i]);
-      for (uptr i = 0; i < b->count; i++) {
-        PREFETCH(b->batch[i + kPrefetch]);
+      for (uptr i = 0, count = b->count; i < count; i++) {
+        if (i + kPrefetch < count)
+          PREFETCH(b->batch[i + kPrefetch]);
         cb.Recycle((Node*)b->batch[i]);
       }
       cb.Deallocate(b);