comparison src/share/vm/classfile/verificationType.cpp @ 18052:2373a1f4987c

8036533: Method for correct defaults 8036156: Limit default method hierarchy Summary: Fix protected access checks Reviewed-by: coleenp, lfoltan, acorn, ahgross
author hseigel
date Fri, 09 May 2014 15:21:20 -0400
parents da91efe96a93
children 50e62b688ddc
comparison
equal deleted inserted replaced
18051:21444610cb92 18052:2373a1f4987c
1 /* 1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
40 return bogus_type(); 40 return bogus_type();
41 } 41 }
42 } 42 }
43 43
44 bool VerificationType::is_reference_assignable_from( 44 bool VerificationType::is_reference_assignable_from(
45 const VerificationType& from, ClassVerifier* context, TRAPS) const { 45 const VerificationType& from, ClassVerifier* context,
46 bool from_field_is_protected, TRAPS) const {
46 instanceKlassHandle klass = context->current_class(); 47 instanceKlassHandle klass = context->current_class();
47 if (from.is_null()) { 48 if (from.is_null()) {
48 // null is assignable to any reference 49 // null is assignable to any reference
49 return true; 50 return true;
50 } else if (is_null()) { 51 } else if (is_null()) {
60 Klass* obj = SystemDictionary::resolve_or_fail( 61 Klass* obj = SystemDictionary::resolve_or_fail(
61 name(), Handle(THREAD, klass->class_loader()), 62 name(), Handle(THREAD, klass->class_loader()),
62 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 63 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
63 KlassHandle this_class(THREAD, obj); 64 KlassHandle this_class(THREAD, obj);
64 65
65 if (this_class->is_interface()) { 66 if (this_class->is_interface() && (!from_field_is_protected ||
66 // We treat interfaces as java.lang.Object, including 67 from.name() != vmSymbols::java_lang_Object())) {
67 // java.lang.Cloneable and java.io.Serializable 68 // If we are not trying to access a protected field or method in
69 // java.lang.Object then we treat interfaces as java.lang.Object,
70 // including java.lang.Cloneable and java.io.Serializable.
68 return true; 71 return true;
69 } else if (from.is_object()) { 72 } else if (from.is_object()) {
70 Klass* from_class = SystemDictionary::resolve_or_fail( 73 Klass* from_class = SystemDictionary::resolve_or_fail(
71 from.name(), Handle(THREAD, klass->class_loader()), 74 from.name(), Handle(THREAD, klass->class_loader()),
72 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 75 Handle(THREAD, klass->protection_domain()), true, CHECK_false);
74 } 77 }
75 } else if (is_array() && from.is_array()) { 78 } else if (is_array() && from.is_array()) {
76 VerificationType comp_this = get_component(context, CHECK_false); 79 VerificationType comp_this = get_component(context, CHECK_false);
77 VerificationType comp_from = from.get_component(context, CHECK_false); 80 VerificationType comp_from = from.get_component(context, CHECK_false);
78 if (!comp_this.is_bogus() && !comp_from.is_bogus()) { 81 if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
79 return comp_this.is_assignable_from(comp_from, context, CHECK_false); 82 return comp_this.is_assignable_from(comp_from, context,
83 from_field_is_protected, CHECK_false);
80 } 84 }
81 } 85 }
82 return false; 86 return false;
83 } 87 }
84 88