summaryrefslogtreecommitdiff
path: root/yjit/src
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2024-05-31 17:37:21 -0400
committerAlan Wu <[email protected]>2024-05-31 18:37:13 -0400
commit6c8ae44a388e5c03b7db90376af3652007b574e8 (patch)
tree76a598bb83a42320a8d64700135528b1c5fa0d2a /yjit/src
parentbc40d0609177cd60ba1bc4fd915e03e917c0b79c (diff)
YJIT: Fix out of bounds access when splatting empty array
Previously, we read the last element array even when the array was empty, doing an out-of-bounds access. This sometimes caused a SEGV. [Bug #20496]
Diffstat (limited to 'yjit/src')
-rw-r--r--yjit/src/codegen.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index f426dd87ca..d86f0d1955 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -6953,20 +6953,20 @@ fn push_splat_args(required_args: u32, asm: &mut Assembler) {
asm.cmp(array_len_opnd, required_args.into());
asm.jne(Target::side_exit(Counter::guard_send_splatarray_length_not_equal));
- asm_comment!(asm, "Check last argument is not ruby2keyword hash");
-
- // Need to repeat this here to deal with register allocation
- let array_reg = asm.load(asm.stack_opnd(0));
-
- let ary_opnd = get_array_ptr(asm, array_reg);
-
- let last_array_value = asm.load(Opnd::mem(64, ary_opnd, (required_args as i32 - 1) * (SIZEOF_VALUE as i32)));
+ // Check last element of array if present
+ if required_args > 0 {
+ asm_comment!(asm, "Check last argument is not ruby2keyword hash");
- guard_object_is_not_ruby2_keyword_hash(
- asm,
- last_array_value,
- Counter::guard_send_splatarray_last_ruby2_keywords,
- );
+ // Need to repeat this here to deal with register allocation
+ let array_reg = asm.load(asm.stack_opnd(0));
+ let ary_opnd = get_array_ptr(asm, array_reg);
+ let last_array_value = asm.load(Opnd::mem(64, ary_opnd, (required_args as i32 - 1) * (SIZEOF_VALUE as i32)));
+ guard_object_is_not_ruby2_keyword_hash(
+ asm,
+ last_array_value,
+ Counter::guard_send_splatarray_last_ruby2_keywords,
+ );
+ }
asm_comment!(asm, "Push arguments from array");
let array_opnd = asm.stack_pop(1);