93 // - to check for javac bug fixes that happened after 1.5 |
93 // - to check for javac bug fixes that happened after 1.5 |
94 // - also used as the max version when running in jdk6 |
94 // - also used as the max version when running in jdk6 |
95 #define JAVA_6_VERSION 50 |
95 #define JAVA_6_VERSION 50 |
96 |
96 |
97 // Used for backward compatibility reasons: |
97 // Used for backward compatibility reasons: |
98 // - to check NameAndType_info signatures more aggressively |
|
99 // - to disallow argument and require ACC_STATIC for <clinit> methods |
98 // - to disallow argument and require ACC_STATIC for <clinit> methods |
100 #define JAVA_7_VERSION 51 |
99 #define JAVA_7_VERSION 51 |
101 |
100 |
102 // Extension method support. |
101 // Extension method support. |
103 #define JAVA_8_VERSION 52 |
102 #define JAVA_8_VERSION 52 |
562 // check the name, even if _cp_patches will overwrite it |
561 // check the name, even if _cp_patches will overwrite it |
563 verify_legal_class_name(class_name, CHECK); |
562 verify_legal_class_name(class_name, CHECK); |
564 break; |
563 break; |
565 } |
564 } |
566 case JVM_CONSTANT_NameAndType: { |
565 case JVM_CONSTANT_NameAndType: { |
567 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
566 if (_need_verify) { |
568 const int sig_index = cp->signature_ref_index_at(index); |
567 const int sig_index = cp->signature_ref_index_at(index); |
569 const int name_index = cp->name_ref_index_at(index); |
568 const int name_index = cp->name_ref_index_at(index); |
570 const Symbol* const name = cp->symbol_at(name_index); |
569 const Symbol* const name = cp->symbol_at(name_index); |
571 const Symbol* const sig = cp->symbol_at(sig_index); |
570 const Symbol* const sig = cp->symbol_at(sig_index); |
572 guarantee_property(sig->utf8_length() != 0, |
571 guarantee_property(sig->utf8_length() != 0, |
573 "Illegal zero length constant pool entry at %d in class %s", |
572 "Illegal zero length constant pool entry at %d in class %s", |
574 sig_index, CHECK); |
573 sig_index, CHECK); |
|
574 guarantee_property(name->utf8_length() != 0, |
|
575 "Illegal zero length constant pool entry at %d in class %s", |
|
576 name_index, CHECK); |
|
577 |
575 if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { |
578 if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { |
|
579 // Format check method name and signature |
|
580 verify_legal_method_name(name, CHECK); |
576 verify_legal_method_signature(name, sig, CHECK); |
581 verify_legal_method_signature(name, sig, CHECK); |
577 } else { |
582 } else { |
|
583 // Format check field name and signature |
|
584 verify_legal_field_name(name, CHECK); |
578 verify_legal_field_signature(name, sig, CHECK); |
585 verify_legal_field_signature(name, sig, CHECK); |
579 } |
586 } |
580 } |
587 } |
581 break; |
588 break; |
582 } |
589 } |
593 const int signature_ref_index = |
600 const int signature_ref_index = |
594 cp->signature_ref_index_at(name_and_type_ref_index); |
601 cp->signature_ref_index_at(name_and_type_ref_index); |
595 const Symbol* const name = cp->symbol_at(name_ref_index); |
602 const Symbol* const name = cp->symbol_at(name_ref_index); |
596 const Symbol* const signature = cp->symbol_at(signature_ref_index); |
603 const Symbol* const signature = cp->symbol_at(signature_ref_index); |
597 if (tag == JVM_CONSTANT_Fieldref) { |
604 if (tag == JVM_CONSTANT_Fieldref) { |
598 verify_legal_field_name(name, CHECK); |
605 if (_need_verify) { |
599 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
606 // Field name and signature are verified above, when iterating NameAndType_info. |
600 // Signature is verified above, when iterating NameAndType_info. |
607 // Need only to be sure signature is non-zero length and the right type. |
601 // Need only to be sure it's non-zero length and the right type. |
|
602 if (signature->utf8_length() == 0 || |
608 if (signature->utf8_length() == 0 || |
603 signature->byte_at(0) == JVM_SIGNATURE_FUNC) { |
609 signature->byte_at(0) == JVM_SIGNATURE_FUNC) { |
604 throwIllegalSignature( |
610 throwIllegalSignature("Field", name, signature, CHECK); |
605 "Field", name, signature, CHECK); |
|
606 } |
611 } |
607 } else { |
|
608 verify_legal_field_signature(name, signature, CHECK); |
|
609 } |
612 } |
610 } else { |
613 } else { |
611 verify_legal_method_name(name, CHECK); |
614 if (_need_verify) { |
612 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
615 // Method name and signature are verified above, when iterating NameAndType_info. |
613 // Signature is verified above, when iterating NameAndType_info. |
616 // Need only to be sure signature is non-zero length and the right type. |
614 // Need only to be sure it's non-zero length and the right type. |
|
615 if (signature->utf8_length() == 0 || |
617 if (signature->utf8_length() == 0 || |
616 signature->byte_at(0) != JVM_SIGNATURE_FUNC) { |
618 signature->byte_at(0) != JVM_SIGNATURE_FUNC) { |
617 throwIllegalSignature( |
619 throwIllegalSignature("Method", name, signature, CHECK); |
618 "Method", name, signature, CHECK); |
|
619 } |
620 } |
620 } else { |
|
621 verify_legal_method_signature(name, signature, CHECK); |
|
622 } |
621 } |
623 if (tag == JVM_CONSTANT_Methodref) { |
622 // 4509014: If a class method name begins with '<', it must be "<init>" |
624 // 4509014: If a class method name begins with '<', it must be "<init>". |
623 const unsigned int name_len = name->utf8_length(); |
625 assert(name != NULL, "method name in constant pool is null"); |
624 if (tag == JVM_CONSTANT_Methodref && |
626 const unsigned int name_len = name->utf8_length(); |
625 name_len != 0 && |
627 if (name_len != 0 && name->byte_at(0) == '<') { |
626 name->byte_at(0) == '<' && |
628 if (name != vmSymbols::object_initializer_name()) { |
627 name != vmSymbols::object_initializer_name()) { |
629 classfile_parse_error( |
628 classfile_parse_error( |
630 "Bad method name at constant pool index %u in class file %s", |
629 "Bad method name at constant pool index %u in class file %s", |
631 name_ref_index, CHECK); |
630 name_ref_index, CHECK); |
632 } |
|
633 } |
|
634 } |
631 } |
635 } |
632 } |
636 break; |
633 break; |
637 } |
634 } |
638 case JVM_CONSTANT_MethodHandle: { |
635 case JVM_CONSTANT_MethodHandle: { |
4841 if (p && (p - signature) > 1 && p[0] == ';') { |
4838 if (p && (p - signature) > 1 && p[0] == ';') { |
4842 return p + 1; |
4839 return p + 1; |
4843 } |
4840 } |
4844 } |
4841 } |
4845 else { |
4842 else { |
4846 // 4900761: For class version > 48, any unicode is allowed in class name. |
4843 // Skip leading 'L' and ignore first appearance of ';' |
4847 length--; |
4844 length--; |
4848 signature++; |
4845 signature++; |
4849 while (length > 0 && signature[0] != ';') { |
4846 char* c = strchr((char*) signature, ';'); |
4850 if (signature[0] == '.') { |
4847 // Format check signature |
4851 classfile_parse_error("Class name contains illegal character '.' in descriptor in class file %s", CHECK_0); |
4848 if (c != NULL) { |
|
4849 ResourceMark rm(THREAD); |
|
4850 int newlen = c - (char*) signature; |
|
4851 char* sig = NEW_RESOURCE_ARRAY(char, newlen + 1); |
|
4852 strncpy(sig, signature, newlen); |
|
4853 sig[newlen] = '\0'; |
|
4854 |
|
4855 bool legal = verify_unqualified_name(sig, newlen, LegalClass); |
|
4856 if (!legal) { |
|
4857 classfile_parse_error("Class name contains illegal character " |
|
4858 "in descriptor in class file %s", |
|
4859 CHECK_0); |
|
4860 return NULL; |
4852 } |
4861 } |
4853 length--; |
4862 return signature + newlen + 1; |
4854 signature++; |
4863 } |
4855 } |
4864 } |
4856 if (signature[0] == ';') { return signature + 1; } |
|
4857 } |
|
4858 |
|
4859 return NULL; |
4865 return NULL; |
4860 } |
4866 } |
4861 case JVM_SIGNATURE_ARRAY: |
4867 case JVM_SIGNATURE_ARRAY: |
4862 array_dim++; |
4868 array_dim++; |
4863 if (array_dim > 255) { |
4869 if (array_dim > 255) { |