summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-25 15:05:37 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-25 15:05:37 +0000
commit9c931b853b99f67964ff7948770031713ad21940 (patch)
treec688266e5c7e24da343e2f1b3e1c2debd5906ac7
parentfb72e453f9e141f182a542dc03b6d95267a3737f (diff)
* vm_insnhelper.c (vm_search_superclass): avoid control frame
stack overrun. currently super() in Proc created in a method defined by Module#define_method raise NoMethodError. [Bug #4881] * test/ruby/test_method.rb t_super_in_proc_from_define_method): add test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--test/ruby/test_method.rb14
-rw-r--r--vm_insnhelper.c5
3 files changed, 27 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 585d8db1a7..6dcf0ef5b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat Jun 25 23:45:30 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
+
+ * vm_insnhelper.c (vm_search_superclass): avoid control frame
+ stack overrun. currently super() in Proc created in a method
+ defined by Module#define_method raise NoMethodError. [Bug #4881]
+ * test/ruby/test_method.rb t_super_in_proc_from_define_method):
+ add test for it.
+
Sat Jun 25 23:23:14 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
* thread.c (sleep_forever): now Kernel#sleep don't wakeup by
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 90f7ddacde..1da32791f7 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -233,6 +233,20 @@ class TestMethod < Test::Unit::TestCase
end
end
+ def test_super_in_proc_from_define_method
+ c1 = Class.new {
+ def m
+ :m1
+ end
+ }
+ c2 = Class.new(c1) { define_method(:m) { Proc.new { super() } } }
+ # c2.new.m.call should return :m1, but currently it raise NoMethodError.
+ # see [Bug #4881] and [Bug #3136]
+ assert_raise(NoMethodError) {
+ c2.new.m.call
+ }
+ end
+
def test_clone
o = Object.new
def o.foo; :foo; end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index bd03c69395..366ac4a467 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1410,9 +1410,14 @@ vm_search_superclass(rb_control_frame_t *reg_cfp, rb_iseq_t *iseq,
}
while (lcfp->iseq != iseq) {
+ rb_thread_t *th = GET_THREAD();
VALUE *tdfp = GET_PREV_DFP(lcfp->dfp);
while (1) {
lcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(lcfp);
+ if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, lcfp)) {
+ rb_raise(rb_eNoMethodError,
+ "super called outside of method");
+ }
if (lcfp->dfp == tdfp) {
break;
}