Mercurial > hg > graal-jvmci-8
comparison src/share/vm/classfile/classFileParser.cpp @ 24027:9d07e8518392
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
Summary: Detect zero length signatures and throw ClassFormatError before bad dereference occurs
Reviewed-by: hseigel
author | poonam |
---|---|
date | Tue, 12 Jul 2016 22:31:57 +0000 |
parents | d109bda16490 |
children | e828a0e2a4bc |
comparison
equal
deleted
inserted
replaced
24026:e901fb8a6f95 | 24027:9d07e8518392 |
---|---|
535 if (_need_verify && _major_version >= JAVA_7_VERSION) { | 535 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
536 int sig_index = cp->signature_ref_index_at(index); | 536 int sig_index = cp->signature_ref_index_at(index); |
537 int name_index = cp->name_ref_index_at(index); | 537 int name_index = cp->name_ref_index_at(index); |
538 Symbol* name = cp->symbol_at(name_index); | 538 Symbol* name = cp->symbol_at(name_index); |
539 Symbol* sig = cp->symbol_at(sig_index); | 539 Symbol* sig = cp->symbol_at(sig_index); |
540 guarantee_property(sig->utf8_length() != 0, | |
541 "Illegal zero length constant pool entry at %d in class %s", | |
542 sig_index, CHECK_(nullHandle)); | |
540 if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { | 543 if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { |
541 verify_legal_method_signature(name, sig, CHECK_(nullHandle)); | 544 verify_legal_method_signature(name, sig, CHECK_(nullHandle)); |
542 } else { | 545 } else { |
543 verify_legal_field_signature(name, sig, CHECK_(nullHandle)); | 546 verify_legal_field_signature(name, sig, CHECK_(nullHandle)); |
544 } | 547 } |
558 Symbol* signature = cp->symbol_at(signature_ref_index); | 561 Symbol* signature = cp->symbol_at(signature_ref_index); |
559 if (tag == JVM_CONSTANT_Fieldref) { | 562 if (tag == JVM_CONSTANT_Fieldref) { |
560 verify_legal_field_name(name, CHECK_(nullHandle)); | 563 verify_legal_field_name(name, CHECK_(nullHandle)); |
561 if (_need_verify && _major_version >= JAVA_7_VERSION) { | 564 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
562 // Signature is verified above, when iterating NameAndType_info. | 565 // Signature is verified above, when iterating NameAndType_info. |
563 // Need only to be sure it's the right type. | 566 // Need only to be sure it's non-zero length and the right type. |
564 if (signature->byte_at(0) == JVM_SIGNATURE_FUNC) { | 567 if (signature->utf8_length() == 0 || |
568 signature->byte_at(0) == JVM_SIGNATURE_FUNC) { | |
565 throwIllegalSignature( | 569 throwIllegalSignature( |
566 "Field", name, signature, CHECK_(nullHandle)); | 570 "Field", name, signature, CHECK_(nullHandle)); |
567 } | 571 } |
568 } else { | 572 } else { |
569 verify_legal_field_signature(name, signature, CHECK_(nullHandle)); | 573 verify_legal_field_signature(name, signature, CHECK_(nullHandle)); |
570 } | 574 } |
571 } else { | 575 } else { |
572 verify_legal_method_name(name, CHECK_(nullHandle)); | 576 verify_legal_method_name(name, CHECK_(nullHandle)); |
573 if (_need_verify && _major_version >= JAVA_7_VERSION) { | 577 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
574 // Signature is verified above, when iterating NameAndType_info. | 578 // Signature is verified above, when iterating NameAndType_info. |
575 // Need only to be sure it's the right type. | 579 // Need only to be sure it's non-zero length and the right type. |
576 if (signature->byte_at(0) != JVM_SIGNATURE_FUNC) { | 580 if (signature->utf8_length() == 0 || |
581 signature->byte_at(0) != JVM_SIGNATURE_FUNC) { | |
577 throwIllegalSignature( | 582 throwIllegalSignature( |
578 "Method", name, signature, CHECK_(nullHandle)); | 583 "Method", name, signature, CHECK_(nullHandle)); |
579 } | 584 } |
580 } else { | 585 } else { |
581 verify_legal_method_signature(name, signature, CHECK_(nullHandle)); | 586 verify_legal_method_signature(name, signature, CHECK_(nullHandle)); |
582 } | 587 } |
583 if (tag == JVM_CONSTANT_Methodref) { | 588 if (tag == JVM_CONSTANT_Methodref) { |
584 // 4509014: If a class method name begins with '<', it must be "<init>". | 589 // 4509014: If a class method name begins with '<', it must be "<init>". |
585 assert(name != NULL, "method name in constant pool is null"); | 590 assert(name != NULL, "method name in constant pool is null"); |
586 unsigned int name_len = name->utf8_length(); | 591 unsigned int name_len = name->utf8_length(); |
587 assert(name_len > 0, "bad method name"); // already verified as legal name | 592 if (name_len != 0 && name->byte_at(0) == '<') { |
588 if (name->byte_at(0) == '<') { | |
589 if (name != vmSymbols::object_initializer_name()) { | 593 if (name != vmSymbols::object_initializer_name()) { |
590 classfile_parse_error( | 594 classfile_parse_error( |
591 "Bad method name at constant pool index %u in class file %s", | 595 "Bad method name at constant pool index %u in class file %s", |
592 name_ref_index, CHECK_(nullHandle)); | 596 name_ref_index, CHECK_(nullHandle)); |
593 } | 597 } |