[compiler-rt] r190132 - [msan] make calloc crash instead of returning 0 on overflow (controlled by the allocator_may_return_null flag)
Kostya Serebryany
kcc at google.com
Fri Sep 6 03:58:55 PDT 2013
Author: kcc
Date: Fri Sep 6 05:58:55 2013
New Revision: 190132
URL: http://llvm.org/viewvc/llvm-project?rev=190132&view=rev
Log:
[msan] make calloc crash instead of returning 0 on overflow (controlled by the allocator_may_return_null flag)
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=190132&r1=190131&r2=190132&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Fri Sep 6 05:58:55 2013
@@ -794,7 +794,8 @@ INTERCEPTOR(SSIZE_T, recvfrom, int fd, v
}
INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) {
- if (CallocShouldReturnNullDueToOverflow(size, nmemb)) return 0;
+ if (CallocShouldReturnNullDueToOverflow(size, nmemb))
+ return AllocatorReturnNull();
GET_MALLOC_STACK_TRACE;
if (!msan_inited) {
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=190132&r1=190131&r2=190132&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Fri Sep 6 05:58:55 2013
@@ -2921,7 +2921,9 @@ TEST(MemorySanitizer, CallocOverflow) {
size_t kArraySize = 4096;
volatile size_t kMaxSizeT = std::numeric_limits<size_t>::max();
volatile size_t kArraySize2 = kMaxSizeT / kArraySize + 10;
- void *p = calloc(kArraySize, kArraySize2); // Should return 0.
+ void *p = 0;
+ EXPECT_DEATH(p = calloc(kArraySize, kArraySize2),
+ "llocator is terminating the process instead of returning 0");
EXPECT_EQ(0L, Ident(p));
}
More information about the llvm-commits
mailing list