vm_trace.c: trace_func safe level check

* vm_trace.c (set_trace_func, thread_{add,set}_trace_func_m): check
  safe level as well as 1.8.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-01-29 07:50:27 +00:00
Родитель b0c4ac7779
Коммит e26c2bc21b
3 изменённых файлов: 43 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Jan 29 16:50:25 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_trace.c (set_trace_func, thread_{add,set}_trace_func_m): check
safe level as well as 1.8.
Tue Jan 29 16:49:19 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (rb_mod_method_arity): return original arity of the method if

Просмотреть файл

@ -397,6 +397,38 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_equal(self, ok, bug3921)
end
def assert_security_error_safe4
func = lambda {
$SAFE = 4
proc {yield}
}.call
assert_raise(SecurityError, &func)
end
def test_set_safe4
assert_security_error_safe4 do
set_trace_func(lambda {|*|})
end
end
def test_thread_set_safe4
th = Thread.start {sleep}
assert_security_error_safe4 do
th.set_trace_func(lambda {|*|})
end
ensure
th.kill
end
def test_thread_add_safe4
th = Thread.start {sleep}
assert_security_error_safe4 do
th.add_trace_func(lambda {|*|})
end
ensure
th.kill
end
class << self
define_method(:method_added, Module.method(:method_added))
end

Просмотреть файл

@ -443,6 +443,8 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU
static VALUE
set_trace_func(VALUE obj, VALUE trace)
{
rb_secure(4);
rb_remove_event_hook(call_trace_func);
if (NIL_P(trace)) {
@ -479,6 +481,8 @@ static VALUE
thread_add_trace_func_m(VALUE obj, VALUE trace)
{
rb_thread_t *th;
rb_secure(4);
GetThreadPtr(obj, th);
thread_add_trace_func(th, trace);
return trace;
@ -498,6 +502,8 @@ static VALUE
thread_set_trace_func_m(VALUE obj, VALUE trace)
{
rb_thread_t *th;
rb_secure(4);
GetThreadPtr(obj, th);
rb_threadptr_remove_event_hook(th, call_trace_func, Qundef);