From 8f745b77289101f26a500697d0fbcdea3f63bf03 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 23 May 2023 14:54:36 +0900 Subject: [PATCH] vm.c (OP_ENTER): fix issues by unreferenced `kdict` and `blk` There's short a period where kdict and blk are not pointed from the stack. --- src/vm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vm.c b/src/vm.c index 415c1efbb..9a36a515a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2101,6 +2101,8 @@ RETRY_TRY_BLOCK: else { mrb_int rnum = 0; if (argv0 != argv) { + mrb_gc_protect(mrb, blk); + mrb_gc_protect(mrb, kdict); value_move(®s[1], argv, m1+o); } if (r) { @@ -2117,11 +2119,12 @@ RETRY_TRY_BLOCK: /* need to be update blk first to protect blk from GC */ mrb_int const kw_pos = len + kd; /* where kwhash should be */ mrb_int const blk_pos = kw_pos + 1; /* where block should be */ - regs[blk_pos] = blk; /* move block */ + regs[blk_pos] = blk; /* move block */ if (kd) { - if (mrb_nil_p(kdict)) + if (mrb_nil_p(kdict)) { kdict = mrb_hash_new_capa(mrb, 0); - regs[kw_pos] = kdict; /* set kwhash */ + } + regs[kw_pos] = kdict; /* set kwhash */ ci->nk = 15; }