vm.c: add type check before calling mrb_hash_size() on keyword dict

the keyword argument handling code was checking if kdict is not nil
before calling mrb_hash_size(), but didn't verify it's actually a hash.
malformed bytecode could cause a non-hash value to be stored in the
keyword dictionary register, leading to a NULL pointer dereference in
h_size(). add mrb_hash_p() check to prevent the crash.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-11-16 19:38:33 +09:00
parent 40b0cb98f7
commit 1c7a0d4e96
+1 -1
View File
@@ -2440,7 +2440,7 @@ RETRY_TRY_BLOCK:
kdict = regs[mrb_ci_kidx(ci)];
}
if (!kd) {
if (!mrb_nil_p(kdict) && mrb_hash_size(mrb, kdict) > 0) {
if (!mrb_nil_p(kdict) && mrb_hash_p(kdict) && mrb_hash_size(mrb, kdict) > 0) {
if (argc < 14) {
ci->n++;
argc++; /* include kdict in normal arguments */