Skip to content

Commit e147516

Browse files
check if flags segment is valid, if not set ep to the right ep
1 parent 11e4f99 commit e147516

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

vm_insnhelper.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -781,26 +781,36 @@ env_method_entry_unchecked(VALUE obj, int can_be_svar)
781781
}
782782

783783
const rb_callable_method_entry_t *
784-
rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
785-
{
786-
const VALUE *ep = cfp->ep;
787-
rb_callable_method_entry_t *me;
788-
789-
while (!VM_ENV_LOCAL_P(ep)) {
790-
if ((me = check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
791-
ep = VM_ENV_PREV_EP(ep);
792-
}
784+
rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
785+
{
786+
const VALUE *ep = cfp->ep;
787+
rb_callable_method_entry_t *me;
788+
789+
while (1) {
790+
if (!FIXNUM_P(ep[VM_ENV_DATA_INDEX_FLAGS])) {
791+
ep = ((rb_env_t *)ep[VM_ENV_DATA_INDEX_FLAGS])->ep;
792+
continue;
793+
}
794+
if (VM_ENV_LOCAL_P(ep)) break; /* ep[0] is Fixnum here — assert is valid */
795+
if ((me = check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
796+
ep = VM_ENV_PREV_EP(ep);
797+
}
793798

794-
return check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], TRUE);
795-
}
799+
return check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], TRUE);
800+
}
796801

797802
const rb_callable_method_entry_t *
798803
rb_vm_frame_method_entry_unchecked(const rb_control_frame_t *cfp)
799804
{
800805
const VALUE *ep = cfp->ep;
801806
rb_callable_method_entry_t *me;
802807

803-
while (!VM_ENV_LOCAL_P_UNCHECKED(ep)) {
808+
while (1) {
809+
if (!FIXNUM_P(ep[VM_ENV_DATA_INDEX_FLAGS])) {
810+
ep = ((rb_env_t *)ep[VM_ENV_DATA_INDEX_FLAGS])->ep;
811+
continue;
812+
}
813+
if (VM_ENV_LOCAL_P_UNCHECKED(ep)) break;
804814
if ((me = env_method_entry_unchecked(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
805815
ep = VM_ENV_PREV_EP_UNCHECKED(ep);
806816
}

0 commit comments

Comments
 (0)