diff options
author | 2023-10-20 16:56:23 +0100 | |
---|---|---|
committer | 2023-11-06 14:21:49 +0000 | |
commit | f987c5cf9c8be959fc1ab62cb0e1c29222cc9fc3 (patch) | |
tree | 858fba4ef5aa2fb63518727385d5bdcaf2539a81 | |
parent | cd576b2e7927067319f6e7e790d5e3f3a1db7a62 (diff) |
Check argument types for unresolved invoke super.
We need to fail verification if the argument types are bogus.
Test: 852-invoke-super
Bug: 28605630
Change-Id: I5a15363a97686cc6beb9ae95b927fcc4753a7202
-rw-r--r-- | runtime/verifier/method_verifier.cc | 5 | ||||
-rw-r--r-- | test/852-invoke-super/expected-stderr.txt | 0 | ||||
-rw-r--r-- | test/852-invoke-super/expected-stdout.txt | 0 | ||||
-rw-r--r-- | test/852-invoke-super/info.txt | 1 | ||||
-rw-r--r-- | test/852-invoke-super/smali/invoke-super.smali | 31 | ||||
-rw-r--r-- | test/852-invoke-super/src/Main.java | 35 | ||||
-rw-r--r-- | test/knownfailures.json | 1 |
7 files changed, 73 insertions, 0 deletions
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 18593a9338..9830bfc8d7 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -4147,12 +4147,14 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgs( // We cannot differentiate on whether this is a class change error or just // a missing method. This will be handled at runtime. Fail(VERIFY_ERROR_NO_METHOD) << "Unable to find referenced class from invoke-super"; + VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); return nullptr; } if (reference_type.GetClass()->IsInterface()) { if (!GetDeclaringClass().HasClass()) { Fail(VERIFY_ERROR_NO_CLASS) << "Unable to resolve the full class of 'this' used in an" << "interface invoke-super"; + VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); return nullptr; } else if (!reference_type.IsStrictlyAssignableFrom(GetDeclaringClass(), this)) { Fail(VERIFY_ERROR_CLASS_CHANGE) @@ -4161,6 +4163,7 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgs( << dex_file_->PrettyMethod(dex_method_idx_) << " to method " << dex_file_->PrettyMethod(method_idx) << " references " << "non-super-interface type " << mirror::Class::PrettyClass(reference_type.GetClass()); + VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); return nullptr; } } else { @@ -4169,6 +4172,7 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgs( Fail(VERIFY_ERROR_NO_METHOD) << "unknown super class in invoke-super from " << dex_file_->PrettyMethod(dex_method_idx_) << " to super " << res_method->PrettyMethod(); + VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); return nullptr; } if (!reference_type.IsStrictlyAssignableFrom(GetDeclaringClass(), this) || @@ -4178,6 +4182,7 @@ ArtMethod* MethodVerifier<kVerifierDebug>::VerifyInvocationArgs( << " to super " << super << "." << res_method->GetName() << res_method->GetSignature(); + VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); return nullptr; } } diff --git a/test/852-invoke-super/expected-stderr.txt b/test/852-invoke-super/expected-stderr.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/852-invoke-super/expected-stderr.txt diff --git a/test/852-invoke-super/expected-stdout.txt b/test/852-invoke-super/expected-stdout.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/852-invoke-super/expected-stdout.txt diff --git a/test/852-invoke-super/info.txt b/test/852-invoke-super/info.txt new file mode 100644 index 0000000000..38447d4770 --- /dev/null +++ b/test/852-invoke-super/info.txt @@ -0,0 +1 @@ +Regression test on checking argument types for unresolved invoke-super. diff --git a/test/852-invoke-super/smali/invoke-super.smali b/test/852-invoke-super/smali/invoke-super.smali new file mode 100644 index 0000000000..6fb9c35ff1 --- /dev/null +++ b/test/852-invoke-super/smali/invoke-super.smali @@ -0,0 +1,31 @@ +# +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.class public LZ; +.super LA; + +.method public constructor <init>()V +.registers 1 + invoke-direct {v0}, LA;-><init>()V + return-void +.end method + +.method public foo()V +.registers 3 + new-instance v0, LY; + invoke-direct {v0}, LY;-><init>()V + invoke-super {v0, v0}, LY;->foo()V + return-void +.end method diff --git a/test/852-invoke-super/src/Main.java b/test/852-invoke-super/src/Main.java new file mode 100644 index 0000000000..317dde58a0 --- /dev/null +++ b/test/852-invoke-super/src/Main.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + public void foo() { } +} + +class Y extends A { + public void foo() { super.foo(); } +} + +public class Main { + + public static void main(String[] args) throws Exception { + try { + Class.forName("Z"); + throw new Error("Expected VerifyError"); + } catch (VerifyError e) { + // Expected. + } + } +} diff --git a/test/knownfailures.json b/test/knownfailures.json index 5bb15e0bda..a49865248a 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -1030,6 +1030,7 @@ "823-cha-inlining", "842-vdex-hard-failure", "850-checker-branches", + "852-invoke-super", "900-hello-plugin", "901-hello-ti-agent", "903-hello-tagging", |