From c2197bf82171ca2dad6f7ef67521fdd30a245d9c Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 16 Dec 2021 15:08:07 -0800 Subject: YJIT: Fix check for required kwargs Previously, YJIT would not check that all the required keywords were specified in the case that there were optional arguments specified. In this case YJIT would incorrectly call the method with invalid arguments. --- yjit_codegen.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'yjit_codegen.c') diff --git a/yjit_codegen.c b/yjit_codegen.c index 3782d8eea3..b18ec44c7a 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -3562,6 +3562,8 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r // keyword parameters. const struct rb_iseq_param_keyword *keyword = iseq->body->param.keyword; + int required_kwargs_filled = 0; + if (keyword->num > 30) { // We have so many keywords that (1 << num) encoded as a FIXNUM // (which shifts it left one more) no longer fits inside a 32-bit @@ -3604,9 +3606,16 @@ gen_send_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r GEN_COUNTER_INC(cb, send_iseq_kwargs_mismatch); return YJIT_CANT_COMPILE; } + + // Keep a count to ensure all required kwargs are specified + if (callee_idx < keyword->required_num) { + required_kwargs_filled++; + } } - } else if (keyword->required_num != 0) { - // No keywords provided so if any are required this is a mismatch + } + + RUBY_ASSERT(required_kwargs_filled <= keyword->required_num); + if (required_kwargs_filled != keyword->required_num) { GEN_COUNTER_INC(cb, send_iseq_kwargs_mismatch); return YJIT_CANT_COMPILE; } -- cgit v1.2.3