@@ -792,7 +792,6 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
792792 // Merge with the next instruction
793793 {
794794 u2 index;
795- int target;
796795 VerificationType type, type2;
797796 VerificationType atype;
798797
@@ -1608,9 +1607,8 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16081607 case Bytecodes::_ifle:
16091608 current_frame.pop_stack (
16101609 VerificationType::integer_type (), CHECK_VERIFY (this ));
1611- target = bcs.dest ();
16121610 stackmap_table.check_jump_target (
1613- ¤t_frame, target , CHECK_VERIFY (this ));
1611+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16141612 no_control_flow = false ; break ;
16151613 case Bytecodes::_if_acmpeq :
16161614 case Bytecodes::_if_acmpne :
@@ -1621,19 +1619,16 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16211619 case Bytecodes::_ifnonnull :
16221620 current_frame.pop_stack (
16231621 VerificationType::reference_check (), CHECK_VERIFY (this ));
1624- target = bcs.dest ();
16251622 stackmap_table.check_jump_target
1626- (¤t_frame, target , CHECK_VERIFY (this ));
1623+ (¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16271624 no_control_flow = false ; break ;
16281625 case Bytecodes::_goto :
1629- target = bcs.dest ();
16301626 stackmap_table.check_jump_target (
1631- ¤t_frame, target , CHECK_VERIFY (this ));
1627+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16321628 no_control_flow = true ; break ;
16331629 case Bytecodes::_goto_w :
1634- target = bcs.dest_w ();
16351630 stackmap_table.check_jump_target (
1636- ¤t_frame, target , CHECK_VERIFY (this ));
1631+ ¤t_frame, bcs. bci (), bcs. get_offset_s4 () , CHECK_VERIFY (this ));
16371632 no_control_flow = true ; break ;
16381633 case Bytecodes::_tableswitch :
16391634 case Bytecodes::_lookupswitch :
@@ -2283,15 +2278,14 @@ void ClassVerifier::verify_switch(
22832278 }
22842279 }
22852280 }
2286- int target = bci + default_offset;
2287- stackmap_table->check_jump_target (current_frame, target, CHECK_VERIFY (this ));
2281+ stackmap_table->check_jump_target (current_frame, bci, default_offset, CHECK_VERIFY (this ));
22882282 for (int i = 0 ; i < keys; i++) {
22892283 // Because check_jump_target() may safepoint, the bytecode could have
22902284 // moved, which means 'aligned_bcp' is no good and needs to be recalculated.
22912285 aligned_bcp = align_up (bcs->bcp () + 1 , jintSize);
2292- target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2286+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
22932287 stackmap_table->check_jump_target (
2294- current_frame, target , CHECK_VERIFY (this ));
2288+ current_frame, bci, offset , CHECK_VERIFY (this ));
22952289 }
22962290 NOT_PRODUCT (aligned_bcp = NULL ); // no longer valid at this point
22972291}
@@ -2550,8 +2544,13 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25502544 break ;
25512545
25522546 case Bytecodes::_goto:
2553- case Bytecodes::_goto_w:
2554- target = (opcode == Bytecodes::_goto ? bcs.dest () : bcs.dest_w ());
2547+ case Bytecodes::_goto_w: {
2548+ int offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2 () : bcs.get_offset_s4 ());
2549+ int min_offset = -1 * max_method_code_size;
2550+ // Check offset for overflow
2551+ if (offset < min_offset || offset > max_method_code_size) return false ;
2552+
2553+ target = bci + offset;
25552554 if (visited_branches->contains (bci)) {
25562555 if (bci_stack->is_empty ()) {
25572556 if (handler_stack->is_empty ()) {
@@ -2572,6 +2571,7 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25722571 visited_branches->append (bci);
25732572 }
25742573 break ;
2574+ }
25752575
25762576 // Check that all switch alternatives end in 'athrow' bytecodes. Since it
25772577 // is difficult to determine where each switch alternative ends, parse
@@ -2608,7 +2608,10 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
26082608
26092609 // Push the switch alternatives onto the stack.
26102610 for (int i = 0 ; i < keys; i++) {
2611- u4 target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2611+ int min_offset = -1 * max_method_code_size;
2612+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2613+ if (offset < min_offset || offset > max_method_code_size) return false ;
2614+ u4 target = bci + offset;
26122615 if (target > code_length) return false ;
26132616 bci_stack->push (target);
26142617 }
0 commit comments