[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
Mon Sep 9 12:24:33 PDT 2013


Ooops. That's ok though, that's just a death test.


On Mon, Sep 9, 2013 at 10:25 PM, Bill Wendling <wendling at apple.com> wrote:

> On Sep 6, 2013, at 3:58 AM, Kostya Serebryany <kcc at google.com> wrote:
>
> > 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");
>
> Missing 'A' at the beginning of message.
>
> -bw
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130909/91bb995c/attachment.html>


More information about the llvm-commits mailing list