Bug #5832

意図しないブロック渡しが行われる

Added by Kazuki Tsujimoto over 2 years ago. Updated over 1 year ago.

[ruby-dev:45071]
Status:Closed
Priority:Normal
Assignee:Kazuki Tsujimoto
Category:YARV
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-01-01 trunk 34167) [x86_64-linux] Backport:

Description

=begin
辻本です。

invokeblockfrom_cの呼び出しの際に渡していたブロックが
VM loopから続けて呼び出される別のメソッドにも渡されてしまうケースがあります。

$ ./ruby -ve "
require 'pp'
require 'pathname'

class <<File
alias realpath_orig realpath

def realpath(args)
yield if blockgiven?
realpath
orig(
args)
end
end

pathname = Pathname.new('.')
Class.new do
define_method(:foo) {
pathname.realpath
}
end.new.foo { pp caller }
"
ruby 2.0.0dev (2012-01-01 trunk 34167) [x86_64-linux]
["-e:9:in realpath'",
"-e:17:in
realpath'",
"-e:17:in block (2 levels) in <main>'",
"-e:19:in
'"]

blockptrはフレームに積まれることになるので、
passed_blockに代入する行は単純に削除してしまって良いと思います。

diff --git a/vm.c b/vm.c
index 2f38eee..3ea190f 100644
--- a/vm.c
+++ b/vm.c
@@ -597,7 +597,6 @@ invokeblockfromc(rbthreadt *th, const rbblockt *block,
iseq->local
size - argsize);
ncfp->me = th->passed
me;
th->passedme = 0;
- th->passed
block = blockptr;

if (cref) {
    th->cfp->dfp[-1] = (VALUE)cref;

=end

Associated revisions

Revision 36685
Added by Kazuki Tsujimoto over 1 year ago

  • vm.c (invokeblockfrom_c): fix unintentional block passing. [Bug #5832]

History

#1 Updated by Koichi Sasada almost 2 years ago

見落としていてすみません.

良さそうに見えるので,テストが通れば,テストを追加してコミット頂けませんか.

#2 Updated by Kazuki Tsujimoto over 1 year ago

  • Assignee changed from Koichi Sasada to Kazuki Tsujimoto

レビューありがとうございました。
対応しておきます。

#3 Updated by Kazuki Tsujimoto over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r36685.
Kazuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm.c (invokeblockfrom_c): fix unintentional block passing. [Bug #5832]

Also available in: Atom PDF