From 5d4aad2b1b7e5a941bf0ed87d280333301183a25 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 25 Nov 2014 18:44:07 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_method.rb | 13 +++++++++++++ vm_eval.c | 4 ++-- vm_insnhelper.c | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 9fc2ab10eb..c8b5ff12d3 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -864,4 +864,17 @@ class TestMethod < Test::Unit::TestCase 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 diff --git a/vm_eval.c b/vm_eval.c index 0f2b19053d..1a6f49b08c 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -583,8 +583,8 @@ rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type sc } 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)); } } } diff --git a/vm_insnhelper.c b/vm_insnhelper.c index e442383a04..7bb0aadaa8 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1779,7 +1779,7 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) } } 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;