Skip to content

Commit

Permalink
8152207: Perform array bound checks while getting a length of bytecod…
Browse files Browse the repository at this point in the history
…e instructions

Reviewed-by: sgehwolf, phh
Backport-of: 68c8a74fbe25918ec50711ce10eff65afcc73b93
  • Loading branch information
martinuy committed Aug 13, 2024
1 parent 047b08a commit d4adbe3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions hotspot/src/share/vm/interpreter/bytecodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,16 @@ class Bytecodes: AllStatic {
static Code non_breakpoint_code_at(const Method* method, address bcp);

// Bytecode attributes
static bool is_defined (int code) { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
static bool is_valid (int code) { return 0 <= code && code < number_of_codes; }
static bool is_defined (int code) { return is_valid(code) && flags(code, false) != 0; }
static bool wide_is_defined(int code) { return is_defined(code) && flags(code, true) != 0; }
static const char* name (Code code) { check(code); return _name [code]; }
static BasicType result_type (Code code) { check(code); return _result_type [code]; }
static int depth (Code code) { check(code); return _depth [code]; }
// Note: Length functions must return <=0 for invalid bytecodes.
// Calling check(code) in length functions would throw an unwanted assert.
static int length_for (Code code) { /*no check*/ return _lengths [code] & 0xF; }
static int wide_length_for(Code code) { /*no check*/ return _lengths [code] >> 4; }
static int length_for (Code code) { return is_valid(code) ? _lengths[code] & 0xF : -1; }
static int wide_length_for(Code code) { return is_valid(code) ? _lengths[code] >> 4 : -1; }
static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); }
static Code java_code (Code code) { check(code); return _java_code [code]; }
static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); }
Expand Down
9 changes: 7 additions & 2 deletions jdk/src/share/native/common/check_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -1731,9 +1731,14 @@ static int instruction_length(unsigned char *iptr, unsigned char *end)
}

default: {
if (instruction < 0 || instruction > JVM_OPC_MAX)
return -1;

/* A length of 0 indicates an error. */
int length = opcode_length[instruction];
return (length <= 0) ? -1 : length;
if (opcode_length[instruction] <= 0)
return -1;

return opcode_length[instruction];
}
}
}
Expand Down

1 comment on commit d4adbe3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.