Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicit reference to bug highlighted by
test/msan/dtor-trivial.cpp. Runtime testing for poisoning vtable pointer in dtor. Summary: Runtime testing for vtable ptr poisoning in dtor. Reviewers: eugenis, kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12713 Clean test case & comments. Update tests for vptr poisoning order. Simplify test to rely upon globals. Assertions verify that vtable still accessible from dtors. Testing linear inheritance and multiple inheritance for vtable poisoning. Macros for testing expected failing functions. Rename macros. Removed xfail, modified FileCheck commands, to expect test to crash. llvm-svn: 247763
- Loading branch information
Naomi Musgrave
committed
Sep 16, 2015
1 parent
703835c
commit 36597fa
Showing
4 changed files
with
177 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// Expected to quit due to invalid access when invoking | ||
// function using vtable. | ||
|
||
class A { | ||
public: | ||
int x; | ||
virtual ~A() { | ||
// Should succeed | ||
this->A_Foo(); | ||
} | ||
virtual void A_Foo() {} | ||
}; | ||
|
||
class B : public virtual A { | ||
public: | ||
int y; | ||
virtual ~B() {} | ||
virtual void A_Foo() {} | ||
}; | ||
|
||
class C : public B { | ||
public: | ||
int z; | ||
~C() {} | ||
}; | ||
|
||
class D { | ||
public: | ||
int w; | ||
~D() {} | ||
virtual void D_Foo() {} | ||
}; | ||
|
||
class E : public virtual A, public virtual D { | ||
public: | ||
int u; | ||
~E() {} | ||
void A_Foo() {} | ||
}; | ||
|
||
int main() { | ||
// Simple linear inheritance | ||
C *c = new C(); | ||
c->~C(); | ||
// This fails | ||
#ifdef CVPTR | ||
c->A_Foo(); | ||
#endif | ||
|
||
// Multiple inheritance, so has multiple vtables | ||
E *e = new E(); | ||
e->~E(); | ||
// Both of these fail | ||
#ifdef EAVPTR | ||
e->A_Foo(); | ||
#endif | ||
#ifdef EDVPTR | ||
e->D_Foo(); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t | ||
|
||
// RUN: %clangxx_msan %s -DVPTRA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// RUN: %clangxx_msan %s -DVPTRC=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t | ||
|
||
// Expected to quit due to invalid access when invoking | ||
// function using vtable. | ||
|
||
#include <sanitizer/msan_interface.h> | ||
#include <stdio.h> | ||
#include <assert.h> | ||
|
||
class A { | ||
public: | ||
int x; | ||
~A() {} | ||
virtual void A_Foo() {} | ||
}; | ||
|
||
class B { | ||
public: | ||
int y; | ||
~B() {} | ||
virtual void B_Foo() {} | ||
}; | ||
|
||
class C : public A, public B { | ||
public: | ||
int z; | ||
~C() {} | ||
virtual void C_Foo() {} | ||
}; | ||
|
||
int main() { | ||
A *a = new A(); | ||
a->~A(); | ||
|
||
// Shouldn't be allowed to invoke function via vtable. | ||
#ifdef VPTRA | ||
a->A_Foo(); | ||
#endif | ||
|
||
C *c = new C(); | ||
c->~C(); | ||
|
||
#ifdef VPTRCA | ||
c->A_Foo(); | ||
#endif | ||
|
||
#ifdef VPTRCB | ||
c->B_Foo(); | ||
#endif | ||
|
||
#ifdef VPTRC | ||
c->C_Foo(); | ||
#endif | ||
|
||
return 0; | ||
} |