Fix potential compaction issue in env_copy()
`src_ep[VM_ENV_DATA_INDEX_ME_CREF]` was read out and held without marking across the allocation in vm_env_new(). In case vm_env_new() ran compaction, an invalid reference could have been written into `copied_env`. It might've been hard to actually produce a crash with this issue due to the pinning marking of the field in rb_execution_context_mark().
This commit is contained in:
parent
050806f425
commit
195dbf241f
9
vm.c
9
vm.c
@ -1218,14 +1218,15 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables)
|
||||
|
||||
VALUE *env_body = ZALLOC_N(VALUE, src_env->env_size); // fill with Qfalse
|
||||
VALUE *ep = &env_body[src_env->env_size - 2];
|
||||
ep[VM_ENV_DATA_INDEX_ME_CREF] = src_ep[VM_ENV_DATA_INDEX_ME_CREF];
|
||||
ep[VM_ENV_DATA_INDEX_FLAGS] = src_ep[VM_ENV_DATA_INDEX_FLAGS] | VM_ENV_FLAG_ISOLATED;
|
||||
const rb_env_t *copied_env = vm_env_new(ep, env_body, src_env->env_size, src_env->iseq);
|
||||
|
||||
// Copy after allocations above, since they can move objects in src_ep.
|
||||
RB_OBJ_WRITE(copied_env, &ep[VM_ENV_DATA_INDEX_ME_CREF], src_ep[VM_ENV_DATA_INDEX_ME_CREF]);
|
||||
ep[VM_ENV_DATA_INDEX_FLAGS] = src_ep[VM_ENV_DATA_INDEX_FLAGS] | VM_ENV_FLAG_ISOLATED;
|
||||
if (!VM_ENV_LOCAL_P(src_ep)) {
|
||||
VM_ENV_FLAGS_SET(ep, VM_ENV_FLAG_LOCAL);
|
||||
}
|
||||
|
||||
const rb_env_t *copied_env = vm_env_new(ep, env_body, src_env->env_size, src_env->iseq);
|
||||
|
||||
if (read_only_variables) {
|
||||
for (int i=RARRAY_LENINT(read_only_variables)-1; i>=0; i--) {
|
||||
ID id = NUM2ID(RARRAY_AREF(read_only_variables, i));
|
||||
|
Loading…
x
Reference in New Issue
Block a user