summaryrefslogtreecommitdiff
path: root/yjit_codegen.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-12-06 19:14:34 -0500
committerAlan Wu <XrXr@users.noreply.github.com>2021-12-06 20:27:15 -0500
commit794b9a28b562121426b3b1a19d2e465616af3ac0 (patch)
tree7199b80cfde3f65684c3af592fed795b06e42af2 /yjit_codegen.c
parentb7ea66bc3228635a87125bea69f01779f75c39de (diff)
YJIT: Add integrity checks for blockid
Verify that the iseq idx pair for the block is valid in invalidate_block_version(). While we are at it, bound loop iterating over instructions to `iseq_body->iseq_size`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5222
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r--yjit_codegen.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c
index 8c888fd53a..9c603e240b 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -639,6 +639,7 @@ static block_t *
gen_single_block(blockid_t blockid, const ctx_t *start_ctx, rb_execution_context_t *ec)
{
RUBY_ASSERT(cb != NULL);
+ verify_blockid(blockid);
// Allocate the new block
block_t *block = calloc(1, sizeof(block_t));
@@ -660,6 +661,7 @@ gen_single_block(blockid_t blockid, const ctx_t *start_ctx, rb_execution_context
RUBY_ASSERT(!(blockid.idx == 0 && start_ctx->stack_size > 0));
const rb_iseq_t *iseq = block->blockid.iseq;
+ const unsigned int iseq_size = iseq->body->iseq_size;
uint32_t insn_idx = block->blockid.idx;
const uint32_t starting_insn_idx = insn_idx;
@@ -676,7 +678,7 @@ gen_single_block(blockid_t blockid, const ctx_t *start_ctx, rb_execution_context
block->start_addr = cb_get_write_ptr(cb);
// For each instruction to compile
- for (;;) {
+ while (insn_idx < iseq_size) {
// Get the current pc and opcode
VALUE *pc = yjit_iseq_pc_at_idx(iseq, insn_idx);
int opcode = yjit_opcode_at_pc(iseq, pc);