aboutsummaryrefslogtreecommitdiffstats
path: root/vm_eval.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-10-23 13:27:21 +0900
committerKoichi Sasada <ko1@atdot.net>2020-10-29 23:42:55 +0900
commit07c03bc30984a496558d9e830bc4fb2f8cfb1854 (patch)
tree961a2eaa656943974221bbdf8cae28a9116e5f37 /vm_eval.c
parentbf951c763d00a4aee8f8c896d1a97c387fa8f30e (diff)
downloadruby-07c03bc30984a496558d9e830bc4fb2f8cfb1854.tar.gz
check isolated Proc more strictly
Isolated Proc prohibit to access outer local variables, but it was violated by binding and so on, so they should be error.
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/vm_eval.c b/vm_eval.c
index 3ada33e128..20117bb79d 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1461,6 +1461,23 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind,
VALUE realpath = Qnil;
rb_iseq_t *iseq = NULL;
rb_ast_t *ast;
+ int isolated_depth = 0;
+ {
+ int depth = 1;
+ const VALUE *ep = vm_block_ep(base_block);
+
+ while (1) {
+ if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ISOLATED)) {
+ isolated_depth = depth;
+ break;
+ }
+ else if (VM_ENV_LOCAL_P(ep)) {
+ break;
+ }
+ ep = VM_ENV_PREV_EP(ep);
+ depth++;
+ }
+ }
if (!fname) {
fname = rb_source_location(&line);
@@ -1477,10 +1494,10 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind,
rb_parser_set_context(parser, parent, FALSE);
ast = rb_parser_compile_string_path(parser, fname, src, line);
if (ast->body.root) {
- iseq = rb_iseq_new_with_opt(&ast->body,
- parent->body->location.label,
- fname, realpath, INT2FIX(line),
- parent, ISEQ_TYPE_EVAL, NULL);
+ iseq = rb_iseq_new_eval(&ast->body,
+ parent->body->location.label,
+ fname, realpath, INT2FIX(line),
+ parent, isolated_depth);
}
rb_ast_dispose(ast);