diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-04-06 19:14:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-06 19:14:03 -0700 |
commit | 0b091fdac6ceb33b7379ceddc9a49a79d0e158b2 (patch) | |
tree | 3ec9799bb7c38ce87b24380f8008ed07467f48e5 /vm.c | |
parent | bff12e1a9a726baef8d5d8876669a1506555ec09 (diff) | |
download | ruby-0b091fdac6ceb33b7379ceddc9a49a79d0e158b2.tar.gz |
Raise RuntimeError if Kernel#binding is called from a non-Ruby frame
Check whether the current or previous frame is a Ruby frame in
call_trace_func and rb_tracearg_binding before attempting to
create a binding for the frame.
Fixes [Bug #18487]
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -1235,15 +1235,12 @@ rb_vm_make_binding(const rb_execution_context_t *ec, const rb_control_frame_t *s if (cfp == 0 || ruby_level_cfp == 0) { rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber."); } - - while (1) { - envval = vm_make_env_object(ec, cfp); - if (cfp == ruby_level_cfp) { - break; - } - cfp = rb_vm_get_binding_creatable_next_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); + if (!VM_FRAME_RUBYFRAME_P(src_cfp) && + !VM_FRAME_RUBYFRAME_P(RUBY_VM_PREVIOUS_CONTROL_FRAME(src_cfp))) { + rb_raise(rb_eRuntimeError, "Cannot create Binding object for non-Ruby caller"); } + envval = vm_make_env_object(ec, cfp); bindval = rb_binding_alloc(rb_cBinding); GetBindingPtr(bindval, bind); vm_bind_update_env(bindval, bind, envval); |