Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
llvm-svn: 306746
  • Loading branch information
alekseyshl committed Jun 29, 2017
1 parent dede76f commit 93c1a8c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ struct Allocator {
}

void *Calloc(uptr nmemb, uptr size, BufferedStackTrace *stack) {
if (CallocShouldReturnNullDueToOverflow(size, nmemb))
if (CheckForCallocOverflow(size, nmemb))
return AsanAllocator::FailureHandler::OnBadRequest();
void *ptr = Allocate(nmemb * size, 8, stack, FROM_MALLOC, false);
// If the memory comes from the secondary allocator no need to clear it
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/msan_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void MsanDeallocate(StackTrace *stack, void *p) {
}

void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
if (CallocShouldReturnNullDueToOverflow(size, nmemb))
if (CheckForCallocOverflow(size, nmemb))
return Allocator::FailureHandler::OnBadRequest();
return MsanReallocate(stack, nullptr, nmemb * size, sizeof(u64), true);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void *InternalRealloc(void *addr, uptr size, InternalAllocatorCache *cache) {
}

void *InternalCalloc(uptr count, uptr size, InternalAllocatorCache *cache) {
if (CallocShouldReturnNullDueToOverflow(count, size))
if (CheckForCallocOverflow(count, size))
return InternalAllocator::FailureHandler::OnBadRequest();
void *p = InternalAlloc(count * size, cache);
if (p) internal_memset(p, 0, count * size);
Expand Down Expand Up @@ -202,7 +202,7 @@ void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback) {
low_level_alloc_callback = callback;
}

bool CallocShouldReturnNullDueToOverflow(uptr size, uptr n) {
bool CheckForCallocOverflow(uptr size, uptr n) {
if (!size) return false;
uptr max = (uptr)-1L;
return (max / size) < n;
Expand Down
6 changes: 4 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ struct NoOpMapUnmapCallback {
// Callback type for iterating over chunks.
typedef void (*ForEachChunkCallback)(uptr chunk, void *arg);

// Returns true if calloc(size, n) should return 0 due to overflow in size*n.
bool CallocShouldReturnNullDueToOverflow(uptr size, uptr n);
// Returns true if calloc(size, n) call overflows on size*n calculation.
// The caller should "return POLICY::OnBadRequest();" where POLICY is the
// current allocator failure handling policy.
bool CheckForCallocOverflow(uptr size, uptr n);

#include "sanitizer_allocator_size_class_map.h"
#include "sanitizer_allocator_stats.h"
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_mman.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void *user_alloc(ThreadState *thr, uptr pc, uptr sz, uptr align, bool signal) {
}

void *user_calloc(ThreadState *thr, uptr pc, uptr size, uptr n) {
if (CallocShouldReturnNullDueToOverflow(size, n))
if (CheckForCallocOverflow(size, n))
return Allocator::FailureHandler::OnBadRequest();
void *p = user_alloc(thr, pc, n * size);
if (p)
Expand Down

0 comments on commit 93c1a8c

Please sign in to comment.