[scudo] Fix an edge case in the secondary allocator
Summary:
s/CHECK_LT/CHECK_LE/ in the secondary allocator, as under certain circumstances
Ptr + Size can be equal to MapEnd. This edge case was not found by the current
tests, so those were extended to be able to catch that.
Reviewers: kcc
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D25101
llvm-svn: 282913
diff --git a/compiler-rt/lib/scudo/scudo_allocator.cpp b/compiler-rt/lib/scudo/scudo_allocator.cpp
index 7dd400e..9b86cfd 100644
--- a/compiler-rt/lib/scudo/scudo_allocator.cpp
+++ b/compiler-rt/lib/scudo/scudo_allocator.cpp
@@ -81,9 +81,9 @@
u8 Unused_0_ : 4;
// 2nd 8 bytes
u64 Offset : 20; // Offset from the beginning of the backend
- // allocation to the beginning chunk itself, in
- // multiples of MinAlignment. See comment about its
- // maximum value and test in init().
+ // allocation to the beginning of the chunk itself,
+ // in multiples of MinAlignment. See comment about
+ // its maximum value and test in init().
u64 Unused_1_ : 28;
u16 Salt : 16;
};
diff --git a/compiler-rt/lib/scudo/scudo_allocator_secondary.h b/compiler-rt/lib/scudo/scudo_allocator_secondary.h
index 220ce87..ac739c8 100644
--- a/compiler-rt/lib/scudo/scudo_allocator_secondary.h
+++ b/compiler-rt/lib/scudo/scudo_allocator_secondary.h
@@ -42,7 +42,7 @@
uptr Ptr = MapBeg + sizeof(SecondaryHeader);
// TODO(kostyak): add a random offset to Ptr.
CHECK_GT(Ptr + Size, MapBeg);
- CHECK_LT(Ptr + Size, MapEnd);
+ CHECK_LE(Ptr + Size, MapEnd);
SecondaryHeader *Header = getHeader(Ptr);
Header->MapBeg = MapBeg - PageSize;
Header->MapSize = MapSize + 2 * PageSize;
diff --git a/compiler-rt/lib/scudo/scudo_utils.cpp b/compiler-rt/lib/scudo/scudo_utils.cpp
index f45569e..9e6a351 100644
--- a/compiler-rt/lib/scudo/scudo_utils.cpp
+++ b/compiler-rt/lib/scudo/scudo_utils.cpp
@@ -34,8 +34,8 @@
FORMAT(1, 2)
void NORETURN dieWithMessage(const char *Format, ...) {
- // Our messages are tiny, 128 characters is more than enough.
- char Message[128];
+ // Our messages are tiny, 256 characters is more than enough.
+ char Message[256];
va_list Args;
va_start(Args, Format);
__sanitizer::VSNPrintf(Message, sizeof(Message), Format, Args);