[asan] trying to de-flake new_array_cookie_uaf_test.cc

llvm-svn: 217177
This commit is contained in:
Kostya Serebryany 2014-09-04 18:02:59 +00:00
parent 7c4059eb89
commit d147590492
1 changed files with 16 additions and 6 deletions

View File

@ -9,20 +9,30 @@ int dtor_counter;
struct C {
int x;
~C() {
fprintf(stderr, "DTOR\n");
dtor_counter++;
if (dtor_counter >= 100) {
fprintf(stderr, "Called DTOR too many times\n");
// NO_COOKIE: Called DTOR too many times
exit(1);
}
fprintf(stderr, "DTOR %d\n", dtor_counter);
}
};
__attribute__((noinline)) void Delete(C *c) { delete[] c; }
__attribute__((no_sanitize_address)) void Write42ToCookie(C *c) {
long *p = reinterpret_cast<long*>(c);
p[-1] = 42;
}
int main(int argc, char **argv) {
C *buffer = new C[argc];
delete [] buffer;
Write42ToCookie(buffer);
delete [] buffer;
// COOKIE: DTOR 1
// COOKIE-NOT: DTOR 2
// COOKIE: AddressSanitizer: loaded array cookie from free-d memory
// COOKIE: AddressSanitizer: attempting double-free
// NO_COOKIE: DTOR 1
// NO_COOKIE: DTOR 43
// NO_COOKIE-NOT: DTOR 44
// NO_COOKIE-NOT: AddressSanitizer: loaded array cookie from free-d memory
// NO_COOKIE: AddressSanitizer: attempting double-free
}