Fix bug with verification of constructors
We would incorrectly allow the storing of values into superclass
fields before the superclass constructor was called.
Bug: 26965384
Change-Id: I45b824fbdbfc133663ed6d3306853595b5dc9262
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index 8d5e6ea..1d31408 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -4526,6 +4526,19 @@
if (UNLIKELY(have_pending_hard_failure_)) {
return;
}
+ if (should_adjust) {
+ if (field == nullptr) {
+ Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "Might be accessing a superclass instance field prior "
+ << "to the superclass being initialized in "
+ << PrettyMethod(dex_method_idx_, *dex_file_);
+ } else if (field->GetDeclaringClass() != GetDeclaringClass().GetClass()) {
+ Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "cannot access superclass instance field "
+ << PrettyField(field) << " of a not fully initialized "
+ << "object within the context of "
+ << PrettyMethod(dex_method_idx_, *dex_file_);
+ return;
+ }
+ }
}
const RegType* field_type = nullptr;
if (field != nullptr) {