From 86d46b5459cda15a616e29934b1ddfe4ec788735 Mon Sep 17 00:00:00 2001 From: shugo Date: Tue, 17 Nov 2009 14:53:32 +0000 Subject: [PATCH] * vm_method.c (rb_alias): should raise TypeError if klass is nil. 1.instance_eval { alias to_string to_s } causes SEGV before this fix. * test/ruby/test_alias.rb (test_special_const_alias): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 ++++++++++- test/ruby/test_alias.rb | 8 ++++++++ vm_method.c | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d720571cdb..ff3c1c0c2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ +Tue Nov 17 23:50:06 2009 Shugo Maeda + + * vm_method.c (rb_alias): should raise TypeError if klass is nil. + 1.instance_eval { alias to_string to_s } causes SEGV before this + fix. + + * test/ruby/test_alias.rb (test_special_const_alias): ditto. + Tue Nov 17 17:53:53 2009 Martin Duerst - * enc/big5.c, enc/trans/big5.trans, enc/trans/big5-uao-tbl.rb, + * enc/big5.c, enc/trans/big5.trans, enc/trans/big5-uao-tbl.rb, test/ruby/test-transcode.rb: Added Encoding 'Big5-UAO' and transcoding for it (from Tatsuya Mizuno) (see Bug #1784) @@ -11,6 +19,7 @@ Tue Nov 17 16:26:24 2009 Nobuyoshi Nakada * vm_insnhelper.c (opt_case_dispatch_i): gets rid of type-punning calls. + Mon Nov 16 15:51:53 2009 Shugo Maeda * vm_insnhelper.c (vm_call_method): protected singleton methods of diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb index 7f8a32c529..babd763577 100644 --- a/test/ruby/test_alias.rb +++ b/test/ruby/test_alias.rb @@ -77,4 +77,12 @@ class TestAlias < Test::Unit::TestCase end assert_equal("ABC", x.try(:upcase), '[ruby-dev:38824]') end + + def test_special_const_alias + assert_raise(TypeError) do + 1.instance_eval do + alias to_string to_s + end + end + end end diff --git a/vm_method.c b/vm_method.c index 557583f5aa..d1c68b58f3 100644 --- a/vm_method.c +++ b/vm_method.c @@ -857,6 +857,10 @@ rb_alias(VALUE klass, ID name, ID def) { rb_method_entry_t *orig_me; + if (NIL_P(klass)) { + rb_raise(rb_eTypeError, "no class to make alias"); + } + rb_frozen_class_p(klass); if (klass == rb_cObject) { rb_secure(4);