Skip to content

Commit

Permalink
* backport r32768 from trunk.
Browse files Browse the repository at this point in the history
* vm.c: check if cfp is valid. [Bug #5083] [ruby-dev:44208]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
k-tsj committed Jul 31, 2011
1 parent 1c8fd01 commit 31013d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Sun Jul 31 11:31:07 2011 Kazuki Tsujimoto <kazuki@callcc.net>

* backport r32768 from trunk.

* vm.c: check if cfp is valid. [Bug #5083] [ruby-dev:44208]

Sat Jul 31 01:23:45 2011 Kenta Murata <mrkn@mrkn.jp>

* backport r32762 from trunk.
Expand Down
12 changes: 12 additions & 0 deletions test/ruby/test_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ class << Thread.current
end
INPUT
end

def test_no_valid_cfp
bug5083 = '[ruby-dev:44208]'
error = assert_raise(RuntimeError) do
Thread.new(&Module.method(:nesting)).join
end
assert_equal("Can't call on top of Fiber or Thread", error.message, bug5083)
error = assert_raise(RuntimeError) do
Thread.new(:to_s, &Module.method(:undef_method)).join
end
assert_equal("Can't call on top of Fiber or Thread", error.message, bug5083)
end
end

class TestThreadGroup < Test::Unit::TestCase
Expand Down
11 changes: 11 additions & 0 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ rb_vm_cref(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);

if (cfp == 0) {
rb_raise(rb_eRuntimeError, "Can't call on top of Fiber or Thread");
}
return vm_get_cref(cfp->iseq, cfp->lfp, cfp->dfp);
}

Expand All @@ -875,6 +879,9 @@ rb_vm_cbase(void)
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);

if (cfp == 0) {
rb_raise(rb_eRuntimeError, "Can't call on top of Fiber or Thread");
}
return vm_get_cbase(cfp->iseq, cfp->lfp, cfp->dfp);
}

Expand Down Expand Up @@ -1971,6 +1978,10 @@ m_core_set_postexe(VALUE self, VALUE iseqval)
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
VALUE proc;

if (cfp == 0) {
rb_bug("m_core_set_postexe: unreachable");
}

GetISeqPtr(iseqval, blockiseq);

blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
Expand Down

0 comments on commit 31013d0

Please sign in to comment.