< prev index next >
src/share/vm/classfile/classFileParser.cpp
Print this page
*** 93,103 ****
// - to check for javac bug fixes that happened after 1.5
// - also used as the max version when running in jdk6
#define JAVA_6_VERSION 50
// Used for backward compatibility reasons:
- // - to check NameAndType_info signatures more aggressively
// - to disallow argument and require ACC_STATIC for <clinit> methods
#define JAVA_7_VERSION 51
// Extension method support.
#define JAVA_8_VERSION 52
--- 93,102 ----
*** 562,582 ****
// check the name, even if _cp_patches will overwrite it
verify_legal_class_name(class_name, CHECK);
break;
}
case JVM_CONSTANT_NameAndType: {
! if (_need_verify && _major_version >= JAVA_7_VERSION) {
const int sig_index = cp->signature_ref_index_at(index);
const int name_index = cp->name_ref_index_at(index);
const Symbol* const name = cp->symbol_at(name_index);
const Symbol* const sig = cp->symbol_at(sig_index);
guarantee_property(sig->utf8_length() != 0,
"Illegal zero length constant pool entry at %d in class %s",
sig_index, CHECK);
if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) {
verify_legal_method_signature(name, sig, CHECK);
} else {
verify_legal_field_signature(name, sig, CHECK);
}
}
break;
}
--- 561,589 ----
// check the name, even if _cp_patches will overwrite it
verify_legal_class_name(class_name, CHECK);
break;
}
case JVM_CONSTANT_NameAndType: {
! if (_need_verify) {
const int sig_index = cp->signature_ref_index_at(index);
const int name_index = cp->name_ref_index_at(index);
const Symbol* const name = cp->symbol_at(name_index);
const Symbol* const sig = cp->symbol_at(sig_index);
guarantee_property(sig->utf8_length() != 0,
"Illegal zero length constant pool entry at %d in class %s",
sig_index, CHECK);
+ guarantee_property(name->utf8_length() != 0,
+ "Illegal zero length constant pool entry at %d in class %s",
+ name_index, CHECK);
+
if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) {
+ // Format check Methodref name and signature
+ verify_legal_method_name(name, CHECK);
verify_legal_method_signature(name, sig, CHECK);
} else {
+ // Format check Fieldref name and signature
+ verify_legal_field_name(name, CHECK);
verify_legal_field_signature(name, sig, CHECK);
}
}
break;
}
*** 593,640 ****
const int signature_ref_index =
cp->signature_ref_index_at(name_and_type_ref_index);
const Symbol* const name = cp->symbol_at(name_ref_index);
const Symbol* const signature = cp->symbol_at(signature_ref_index);
if (tag == JVM_CONSTANT_Fieldref) {
! verify_legal_field_name(name, CHECK);
! if (_need_verify && _major_version >= JAVA_7_VERSION) {
! // Signature is verified above, when iterating NameAndType_info.
! // Need only to be sure it's non-zero length and the right type.
if (signature->utf8_length() == 0 ||
signature->byte_at(0) == JVM_SIGNATURE_FUNC) {
! throwIllegalSignature(
! "Field", name, signature, CHECK);
}
- } else {
- verify_legal_field_signature(name, signature, CHECK);
}
} else {
! verify_legal_method_name(name, CHECK);
! if (_need_verify && _major_version >= JAVA_7_VERSION) {
! // Signature is verified above, when iterating NameAndType_info.
! // Need only to be sure it's non-zero length and the right type.
if (signature->utf8_length() == 0 ||
signature->byte_at(0) != JVM_SIGNATURE_FUNC) {
! throwIllegalSignature(
! "Method", name, signature, CHECK);
}
- } else {
- verify_legal_method_signature(name, signature, CHECK);
}
! if (tag == JVM_CONSTANT_Methodref) {
! // 4509014: If a class method name begins with '<', it must be "<init>".
! assert(name != NULL, "method name in constant pool is null");
const unsigned int name_len = name->utf8_length();
! if (name_len != 0 && name->byte_at(0) == '<') {
! if (name != vmSymbols::object_initializer_name()) {
classfile_parse_error(
"Bad method name at constant pool index %u in class file %s",
name_ref_index, CHECK);
}
}
- }
- }
break;
}
case JVM_CONSTANT_MethodHandle: {
const int ref_index = cp->method_handle_index_at(index);
const int ref_kind = cp->method_handle_ref_kind_at(index);
--- 600,637 ----
const int signature_ref_index =
cp->signature_ref_index_at(name_and_type_ref_index);
const Symbol* const name = cp->symbol_at(name_ref_index);
const Symbol* const signature = cp->symbol_at(signature_ref_index);
if (tag == JVM_CONSTANT_Fieldref) {
! if (_need_verify) {
! // Field name and signature are verified above, when iterating NameAndType_info.
! // Need only to be sure signature is non-zero length and the right type.
if (signature->utf8_length() == 0 ||
signature->byte_at(0) == JVM_SIGNATURE_FUNC) {
! throwIllegalSignature("Field", name, signature, CHECK);
}
}
} else {
! if (_need_verify) {
! // Method name and signature are verified above, when iterating NameAndType_info.
! // Need only to be sure signature is non-zero length and the right type.
if (signature->utf8_length() == 0 ||
signature->byte_at(0) != JVM_SIGNATURE_FUNC) {
! throwIllegalSignature("Method", name, signature, CHECK);
}
}
! // 4509014: If a class method name begins with '<', it must be "<init>"
const unsigned int name_len = name->utf8_length();
! if (tag == JVM_CONSTANT_Methodref &&
! name_len != 0 &&
! name->byte_at(0) == '<' &&
! name != vmSymbols::object_initializer_name()) {
classfile_parse_error(
"Bad method name at constant pool index %u in class file %s",
name_ref_index, CHECK);
}
}
break;
}
case JVM_CONSTANT_MethodHandle: {
const int ref_index = cp->method_handle_index_at(index);
const int ref_kind = cp->method_handle_ref_kind_at(index);
*** 4841,4863 ****
if (p && (p - signature) > 1 && p[0] == ';') {
return p + 1;
}
}
else {
! // 4900761: For class version > 48, any unicode is allowed in class name.
length--;
signature++;
! while (length > 0 && signature[0] != ';') {
! if (signature[0] == '.') {
! classfile_parse_error("Class name contains illegal character '.' in descriptor in class file %s", CHECK_0);
}
! length--;
! signature++;
}
- if (signature[0] == ';') { return signature + 1; }
}
-
return NULL;
}
case JVM_SIGNATURE_ARRAY:
array_dim++;
if (array_dim > 255) {
--- 4838,4869 ----
if (p && (p - signature) > 1 && p[0] == ';') {
return p + 1;
}
}
else {
! // Skip leading 'L' and ignore first appearance of ';'
length--;
signature++;
! char* c = strchr((char*) signature, ';');
! // Format check signature
! if (c != NULL) {
! int newlen = c - (char*) signature;
! char* sig = NEW_RESOURCE_ARRAY(char, newlen + 1);
! strncpy(sig, signature, newlen);
! sig[newlen] = '\0';
!
! bool legal = verify_unqualified_name(sig, newlen, LegalClass);
! if (!legal) {
! ResourceMark rm(THREAD);
! classfile_parse_error("Class name contains illegal character "
! "in descriptor in class file %s",
! CHECK_0);
! return NULL;
}
! return signature + newlen + 1;
}
}
return NULL;
}
case JVM_SIGNATURE_ARRAY:
array_dim++;
if (array_dim > 255) {
*** 4867,4877 ****
// The rest of what's there better be a legal signature
signature++;
length--;
void_ok = false;
break;
-
default:
return NULL;
}
}
return NULL;
--- 4873,4882 ----
< prev index next >