class.c: prevent crash in instance_eval; fix #6570

Fixes a null pointer dereference in `find_visibility_scope` when defining a
singleton method inside `instance_eval`.

This was caused by `ci->u.env` being `NULL` in this context. The fix adds a
`NULL` check to prevent the crash.

Co-authored-by: Gemini <gemini@google.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-07-05 18:32:26 +09:00
parent e4b83f688e
commit 0da6df6063
+1 -2
View File
@@ -950,8 +950,7 @@ find_visibility_scope(mrb_state *mrb, const struct RClass *c, int n, mrb_callinf
if (c == NULL) c = mrb_vm_ci_target_class(ci);
if (check_visibility_break(p, c, ci, NULL)) {
mrb_assert(ci->u.env);
*ep = (ci->u.env->tt == MRB_TT_ENV ? ci->u.env : NULL);
*ep = (ci->u.env && ci->u.env->tt == MRB_TT_ENV) ? ci->u.env : NULL;
*cp = ci;
return;
}