summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-09-06 10:58:55 +0000
committerKostya Serebryany <kcc@google.com>2013-09-06 10:58:55 +0000
commit6c5b034d7b1eeae1d64d93c68ed57ec452810784 (patch)
treed77aaa885cf984a62621491d9afe10ee95ce95df /compiler-rt
parentdb12ab7b7c87bcadc7688c07bcbb23a04b433eab (diff)
downloadbcm5719-llvm-6c5b034d7b1eeae1d64d93c68ed57ec452810784.tar.gz
bcm5719-llvm-6c5b034d7b1eeae1d64d93c68ed57ec452810784.zip
[msan] make calloc crash instead of returning 0 on overflow (controlled by the allocator_may_return_null flag)
llvm-svn: 190132
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/msan/msan_interceptors.cc3
-rw-r--r--compiler-rt/lib/msan/tests/msan_test.cc4
2 files changed, 5 insertions, 2 deletions
diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc
index 88c9f86eb37..078e6d4531d 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cc
+++ b/compiler-rt/lib/msan/msan_interceptors.cc
@@ -794,7 +794,8 @@ INTERCEPTOR(SSIZE_T, recvfrom, int fd, void *buf, SIZE_T len, int flags,
}
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.
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc
index bec303501a3..64fe4b5c8eb 100644
--- a/compiler-rt/lib/msan/tests/msan_test.cc
+++ b/compiler-rt/lib/msan/tests/msan_test.cc
@@ -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));
}
OpenPOWER on IntegriCloud