1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1926 return SystemDictionary::resolve_or_fail(
1927 name, Handle(THREAD, loader), Handle(THREAD, protection_domain),
1928 true, CHECK_NULL);
1929 }
1930
1931 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
1932 Klass* target_class,
1933 Symbol* field_name,
1934 Symbol* field_sig,
1935 bool is_method) {
1936 No_Safepoint_Verifier nosafepoint;
1937
1938 // If target class isn't a super class of this class, we don't worry about this case
1939 if (!this_class->is_subclass_of(target_class)) {
1940 return false;
1941 }
1942 // Check if the specified method or field is protected
1943 InstanceKlass* target_instance = InstanceKlass::cast(target_class);
1944 fieldDescriptor fd;
1945 if (is_method) {
1946 Method* m = target_instance->uncached_lookup_method(field_name, field_sig);
1947 if (m != NULL && m->is_protected()) {
1948 if (!this_class->is_same_class_package(m->method_holder())) {
1949 return true;
1950 }
1951 }
1952 } else {
1953 Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd);
1954 if (member_klass != NULL && fd.is_protected()) {
1955 if (!this_class->is_same_class_package(member_klass)) {
1956 return true;
1957 }
1958 }
1959 }
1960 return false;
1961 }
1962
1963 void ClassVerifier::verify_ldc(
1964 int opcode, u2 index, StackMapFrame* current_frame,
1965 constantPoolHandle cp, u2 bci, TRAPS) {
1966 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
2263 // The method must be an <init> method of the indicated class
2264 VerificationType new_class_type = cp_index_to_type(
2265 new_class_index, cp, CHECK_VERIFY(this));
2266 if (!new_class_type.equals(ref_class_type)) {
2267 verify_error(ErrorContext::bad_type(bci,
2268 TypeOrigin::cp(new_class_index, new_class_type),
2269 TypeOrigin::cp(ref_class_index, ref_class_type)),
2270 "Call to wrong <init> method");
2271 return;
2272 }
2273 // According to the VM spec, if the referent class is a superclass of the
2274 // current class, and is in a different runtime package, and the method is
2275 // protected, then the objectref must be the current class or a subclass
2276 // of the current class.
2277 VerificationType objectref_type = new_class_type;
2278 if (name_in_supers(ref_class_type.name(), current_class())) {
2279 Klass* ref_klass = load_class(
2280 ref_class_type.name(), CHECK_VERIFY(this));
2281 Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
2282 vmSymbols::object_initializer_name(),
2283 cp->signature_ref_at(bcs->get_index_u2()));
2284 instanceKlassHandle mh(THREAD, m->method_holder());
2285 if (m->is_protected() && !mh->is_same_class_package(_klass())) {
2286 bool assignable = current_type().is_assignable_from(
2287 objectref_type, this, CHECK_VERIFY(this));
2288 if (!assignable) {
2289 verify_error(ErrorContext::bad_type(bci,
2290 TypeOrigin::cp(new_class_index, objectref_type),
2291 TypeOrigin::implicit(current_type())),
2292 "Bad access to protected <init> method");
2293 return;
2294 }
2295 }
2296 }
2297 current_frame->initialize_object(type, new_class_type);
2298 } else {
2299 verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()),
2300 "Bad operand type when invoking <init>");
2301 return;
2302 }
2303 }
|
1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1926 return SystemDictionary::resolve_or_fail(
1927 name, Handle(THREAD, loader), Handle(THREAD, protection_domain),
1928 true, CHECK_NULL);
1929 }
1930
1931 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
1932 Klass* target_class,
1933 Symbol* field_name,
1934 Symbol* field_sig,
1935 bool is_method) {
1936 No_Safepoint_Verifier nosafepoint;
1937
1938 // If target class isn't a super class of this class, we don't worry about this case
1939 if (!this_class->is_subclass_of(target_class)) {
1940 return false;
1941 }
1942 // Check if the specified method or field is protected
1943 InstanceKlass* target_instance = InstanceKlass::cast(target_class);
1944 fieldDescriptor fd;
1945 if (is_method) {
1946 Method* m = target_instance->uncached_lookup_method(field_name, field_sig, false);
1947 if (m != NULL && m->is_protected()) {
1948 if (!this_class->is_same_class_package(m->method_holder())) {
1949 return true;
1950 }
1951 }
1952 } else {
1953 Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd);
1954 if (member_klass != NULL && fd.is_protected()) {
1955 if (!this_class->is_same_class_package(member_klass)) {
1956 return true;
1957 }
1958 }
1959 }
1960 return false;
1961 }
1962
1963 void ClassVerifier::verify_ldc(
1964 int opcode, u2 index, StackMapFrame* current_frame,
1965 constantPoolHandle cp, u2 bci, TRAPS) {
1966 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
2263 // The method must be an <init> method of the indicated class
2264 VerificationType new_class_type = cp_index_to_type(
2265 new_class_index, cp, CHECK_VERIFY(this));
2266 if (!new_class_type.equals(ref_class_type)) {
2267 verify_error(ErrorContext::bad_type(bci,
2268 TypeOrigin::cp(new_class_index, new_class_type),
2269 TypeOrigin::cp(ref_class_index, ref_class_type)),
2270 "Call to wrong <init> method");
2271 return;
2272 }
2273 // According to the VM spec, if the referent class is a superclass of the
2274 // current class, and is in a different runtime package, and the method is
2275 // protected, then the objectref must be the current class or a subclass
2276 // of the current class.
2277 VerificationType objectref_type = new_class_type;
2278 if (name_in_supers(ref_class_type.name(), current_class())) {
2279 Klass* ref_klass = load_class(
2280 ref_class_type.name(), CHECK_VERIFY(this));
2281 Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
2282 vmSymbols::object_initializer_name(),
2283 cp->signature_ref_at(bcs->get_index_u2()),
2284 false);
2285 instanceKlassHandle mh(THREAD, m->method_holder());
2286 if (m->is_protected() && !mh->is_same_class_package(_klass())) {
2287 bool assignable = current_type().is_assignable_from(
2288 objectref_type, this, CHECK_VERIFY(this));
2289 if (!assignable) {
2290 verify_error(ErrorContext::bad_type(bci,
2291 TypeOrigin::cp(new_class_index, objectref_type),
2292 TypeOrigin::implicit(current_type())),
2293 "Bad access to protected <init> method");
2294 return;
2295 }
2296 }
2297 }
2298 current_frame->initialize_object(type, new_class_type);
2299 } else {
2300 verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()),
2301 "Bad operand type when invoking <init>");
2302 return;
2303 }
2304 }
|