New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local_variables is broken #3710

Closed
i110 opened this Issue Jun 18, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@i110
Contributor

i110 commented Jun 18, 2017

def _generate
  var = 110
  proc {|hoge| p local_variables }
end
_generate.call

outputs [:hoge], but I expect [:hoge, :var] as CRuby does.

As I looked the code, struct REnv * assigned to the generated proc gets unshared when cipop called in OP_RETURN, and that makes the env not enumarated. Is this a mruby's spec or not?

Even if that's a spec, I believe that the following behavior is absolutely a bug.

def _generate
  eval("var = 110; proc {|hoge| p local_variables }")
end

def _call(invisible)
  invisible.call
end

_call(_generate)

says [:hoge, :invisible], but if I'm correct invisible shouldn't appear.
In this case, the env of the generated proc is not unshared due to another callinfo, but mrb_local_variables refers current callinfo stack, so variables not related to the proc appears. As a similar example,

def _generate
  eval("var = 110; proc {|hoge| p local_variables }")
end

def dummy(invisible)
end

Fiber.new {
  ret = _generate
  dummy(nil)
  ret
}.resume.call

outputs the same, [:hoge, :invisible]. In this case, another context's callinfo which gets overwrited by calling dummy function is referred.

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Jun 18, 2017

Member

The first issue is mruby limitation. We will try to address it but it would take time.
The second issue is caused by a bug in eval (create_proc_from_string).

Member

matz commented Jun 18, 2017

The first issue is mruby limitation. We will try to address it but it would take time.
The second issue is caused by a bug in eval (create_proc_from_string).

matz added a commit that referenced this issue Jun 19, 2017

Fixed disclosure of local variables by `eval`; ref #3710
This patch fixes the latter part of #3710. We need to change
`struct REnv` to fix the former part of the issue.
@i110

This comment has been minimized.

Show comment
Hide comment
@i110

i110 Jun 19, 2017

Contributor

Actually I found the first issue when debugging the second one, so I'm not stacked at that if I know that's a limitation. Thanks a lot!

Contributor

i110 commented Jun 19, 2017

Actually I found the first issue when debugging the second one, so I'm not stacked at that if I know that's a limitation. Thanks a lot!

@matz matz closed this in bf1cb87 Jun 20, 2017

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Jun 20, 2017

Member

Oops, issue number was wrong.

Member

matz commented Jun 20, 2017

Oops, issue number was wrong.

@matz matz reopened this Jun 20, 2017

@matz matz referenced this issue Jul 4, 2017

Closed

1.3.0 Changes #3140

@matz matz closed this in 7b88c1a Aug 1, 2017

tsahara added a commit to iij/mruby that referenced this issue Jun 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment