[前][次][番号順一覧][スレッド一覧]

ruby-changes:36490

From: nobu <ko1@a...>
Date: Wed, 26 Nov 2014 03:44:14 +0900 (JST)
Subject: [ruby-changes:36490] nobu:r48572 (trunk): vm_eval.c: preserve encoding

nobu	2014-11-26 03:44:07 +0900 (Wed, 26 Nov 2014)

  New Revision: 48572

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48572

  Log:
    vm_eval.c: preserve encoding
    
    * vm_eval.c (rb_method_call_status): preserve encoding of called method
      name in error messages.
    
    * vm_insnhelper.c (vm_call_method): ditto.

  Modified files:
    trunk/test/ruby/test_method.rb
    trunk/vm_eval.c
    trunk/vm_insnhelper.c
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 48571)
+++ vm_eval.c	(revision 48572)
@@ -583,8 +583,8 @@ rb_method_call_status(rb_thread_t *th, c https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L583
 	    }
 
 	    if (NOEX_SAFE(noex) > th->safe_level) {
-		rb_raise(rb_eSecurityError, "calling insecure method: %s",
-			 rb_id2name(me->called_id));
+		rb_raise(rb_eSecurityError, "calling insecure method: %"PRIsVALUE,
+			 rb_id2str(me->called_id));
 	    }
 	}
     }
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 48571)
+++ vm_insnhelper.c	(revision 48572)
@@ -1779,7 +1779,7 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1779
 		}
 	    }
 	    else if ((noex_safe = NOEX_SAFE(ci->me->flag)) > th->safe_level && (noex_safe > 2)) {
-		rb_raise(rb_eSecurityError, "calling insecure method: %s", rb_id2name(ci->mid));
+		rb_raise(rb_eSecurityError, "calling insecure method: %"PRIsVALUE, rb_id2str(ci->mid));
 	    }
 	    else {
 		goto normal_method_dispatch;
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 48571)
+++ test/ruby/test_method.rb	(revision 48572)
@@ -864,4 +864,17 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L864
     n = 10_000_000
     assert_equal n  , rest_parameter(*(1..n)).size, '[Feature #10440]'
   end
+
+  def test_insecure_method
+    m = "\u{5371 967a}"
+    c = Class.new do
+      proc {$SAFE=3;def foo;end}.call
+      alias_method m, "foo"
+      eval "def bar; #{m}; end"
+    end
+    obj = c.new
+    assert_raise_with_message(SecurityError, /#{m}/) do
+      obj.bar
+    end
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]