<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 5:24 AM, Evgeniy Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There is something wrong with this test on Android on ARM: the offset<br>
is 8 bytes instead of sizeof(void*)==4.<br>
<br>
<a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/13105/steps/run%20asan%20lit%20tests%20%5BAndroid%5D/logs/stdio" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/13105/steps/run%20asan%20lit%20tests%20%5BAndroid%5D/logs/stdio</a><br>
<br>
Also, main() is missing a return statement.<br></blockquote><div><br></div><div>(FWIW main implicitly returns 0 if no return is given in C++ - so this is well defined (though coding styles/etc may vary on whether they prefer to use this language feature or prefer to be explicit))</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, Sep 29, 2014 at 11:40 PM, Kostya Serebryany <<a href="mailto:kcc@google.com">kcc@google.com</a>> wrote:<br>
> Author: kcc<br>
> Date: Mon Sep 29 14:40:56 2014<br>
> New Revision: 218620<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=218620&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=218620&view=rev</a><br>
> Log:<br>
> [asan] add a test for array cookie if the operator new is defined inside the class (the cookie should not be poisoned in such case); update the related comment in asan_poisoning.cc<br>
><br>
> Added:<br>
>     compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc<br>
> Modified:<br>
>     compiler-rt/trunk/lib/asan/asan_poisoning.cc<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=218620&r1=218619&r2=218620&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=218620&r1=218619&r2=218620&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)<br>
> +++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Mon Sep 29 14:40:56 2014<br>
> @@ -252,7 +252,8 @@ uptr __asan_load_cxx_array_cookie(uptr *<br>
>             "expect a double-free report\n");<br>
>      return 0;<br>
>    }<br>
> -  // FIXME: apparently it can be something else; need to find a reproducer.<br>
> +  // The cookie may remain unpoisoned if e.g. it comes from a custom<br>
> +  // operator new defined inside a class.<br>
>    return *p;<br>
>  }<br>
><br>
><br>
> Added: compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc?rev=218620&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc?rev=218620&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc (added)<br>
> +++ compiler-rt/trunk/test/asan/TestCases/Linux/new_array_cookie_with_new_from_class.cc Mon Sep 29 14:40:56 2014<br>
> @@ -0,0 +1,34 @@<br>
> +// Test that we do not poison the array cookie if the operator new is defined<br>
> +// inside the class.<br>
> +// RUN: %clangxx_asan  %s -o %t && %run %t<br>
> +#include <new><br>
> +#include <stdlib.h><br>
> +#include <stdint.h><br>
> +#include <stdio.h><br>
> +#include <assert.h><br>
> +struct Foo {<br>
> +  void *operator new(size_t s) { return Allocate(s); }<br>
> +  void *operator new[] (size_t s) { return Allocate(s); }<br>
> +  ~Foo();<br>
> +  static void *allocated;<br>
> +  static void *Allocate(size_t s) {<br>
> +    assert(!allocated);<br>
> +    return allocated = ::new char[s];<br>
> +  }<br>
> +};<br>
> +<br>
> +Foo::~Foo() {}<br>
> +void *Foo::allocated;<br>
> +<br>
> +Foo *getFoo(size_t n) {<br>
> +  return new Foo[n];<br>
> +}<br>
> +<br>
> +int main() {<br>
> +  Foo *foo = getFoo(10);<br>
> +  fprintf(stderr, "foo  : %p\n", foo);<br>
> +  fprintf(stderr, "alloc: %p\n", Foo::allocated);<br>
> +  assert(reinterpret_cast<uintptr_t>(foo) ==<br>
> +         reinterpret_cast<uintptr_t>(Foo::allocated) + sizeof(void*));<br>
> +  *reinterpret_cast<uintptr_t*>(Foo::allocated) = 42;<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div></div>