Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Unified Diff: base/tools_sanity_unittest.cc

Issue 2131423002: Implement use_cfi_cast to optionally enable cast checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Localize CFI_CAST_CHECK define Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | build/common.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/tools_sanity_unittest.cc
diff --git a/base/tools_sanity_unittest.cc b/base/tools_sanity_unittest.cc
index 8d13837887b854a2dfad5178e1c74ed59687bda3..9075d16f545592eb34cfc724da2d53ec26c2e403 100644
--- a/base/tools_sanity_unittest.cc
+++ b/base/tools_sanity_unittest.cc
@@ -343,6 +343,8 @@ TEST(ToolsSanityTest, AtomicsAreIgnored) {
}
#if defined(CFI_ENFORCEMENT)
+// TODO(krasin): remove CFI_CAST_CHECK, see https://crbug.com/626794.
+#if defined(CFI_CAST_CHECK)
TEST(ToolsSanityTest, BadCast) {
class A {
virtual void f() {}
@@ -355,6 +357,32 @@ TEST(ToolsSanityTest, BadCast) {
A a;
EXPECT_DEATH((void)(B*)&a, "ILL_ILLOPN");
}
-#endif
+#endif // CFI_CAST_CHECK
+
+class A {
+ public:
+ A(): n_(0) {}
+ virtual void f() { n_++; }
+ protected:
+ int n_;
+};
+
+class B: public A {
+ public:
+ void f() override { n_--; }
+};
+
+NOINLINE void KillVptrAndCall(A *obj) {
+ *reinterpret_cast<void **>(obj) = 0;
+ obj->f();
+}
+
+TEST(ToolsSanityTest, BadVirtualCall) {
+ A a;
+ B b;
+ EXPECT_DEATH({ KillVptrAndCall(&a); KillVptrAndCall(&b); }, "ILL_ILLOPN");
+}
+
+#endif // CFI_ENFORCEMENT
} // namespace base
« no previous file with comments | « base/base.gyp ('k') | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698