8132904: Type checking verifier fails to reject assignment from array to an interface

Only allow assignment if interface is Cloneable or Serializable.

Reviewed-by: kamg, gtriantafill, jiangli
This commit is contained in:
Harold Seigel 2015-09-18 07:01:23 -04:00
parent 34a6b43988
commit e7ed6bff90

View File

@ -70,9 +70,12 @@ bool VerificationType::is_reference_assignable_from(
if (this_class->is_interface() && (!from_field_is_protected || if (this_class->is_interface() && (!from_field_is_protected ||
from.name() != vmSymbols::java_lang_Object())) { from.name() != vmSymbols::java_lang_Object())) {
// If we are not trying to access a protected field or method in // If we are not trying to access a protected field or method in
// java.lang.Object then we treat interfaces as java.lang.Object, // java.lang.Object then, for arrays, we only allow assignability
// including java.lang.Cloneable and java.io.Serializable. // to interfaces java.lang.Cloneable and java.io.Serializable.
return true; // Otherwise, we treat interfaces as java.lang.Object.
return !from.is_array() ||
this_class == SystemDictionary::Cloneable_klass() ||
this_class == SystemDictionary::Serializable_klass();
} else if (from.is_object()) { } else if (from.is_object()) {
Klass* from_class = SystemDictionary::resolve_or_fail( Klass* from_class = SystemDictionary::resolve_or_fail(
from.name(), Handle(THREAD, klass->class_loader()), from.name(), Handle(THREAD, klass->class_loader()),