From e9e752c7efe95e7166c7bb59277b6e3afe11851c Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 23 Feb 2024 20:18:41 -0800 Subject: [PATCH] Assert running_iseq before using it When running_iseq happens to be 0, it's better to fail on the assertion rather than referencing the null pointer. --- yjit/src/core.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yjit/src/core.rs b/yjit/src/core.rs index 3843e91e2e..90e6490997 100644 --- a/yjit/src/core.rs +++ b/yjit/src/core.rs @@ -2749,14 +2749,14 @@ fn branch_stub_hit_body(branch_ptr: *const c_void, target_idx: u32, ec: EcPtr) - let original_interp_sp = get_cfp_sp(cfp); let running_iseq = get_cfp_iseq(cfp); + assert_eq!(running_iseq, target_blockid.iseq as _, "each stub expects a particular iseq"); + let reconned_pc = rb_iseq_pc_at_idx(running_iseq, target_blockid.idx.into()); let reconned_sp = original_interp_sp.offset(target_ctx.sp_offset.into()); // Unlike in the interpreter, our `leave` doesn't write to the caller's // SP -- we do it in the returned-to code. Account for this difference. let reconned_sp = reconned_sp.add(target_ctx.is_return_landing().into()); - assert_eq!(running_iseq, target_blockid.iseq as _, "each stub expects a particular iseq"); - // Update the PC in the current CFP, because it may be out of sync in JITted code rb_set_cfp_pc(cfp, reconned_pc);