diff --git a/struct.c b/struct.c index 136ba0a..d478013 100644 --- a/struct.c +++ b/struct.c @@ -154,7 +154,7 @@ rb_struct_modify(VALUE s) { rb_check_frozen(s); if (!OBJ_UNTRUSTED(s) && rb_safe_level() >= 4) - rb_raise(rb_eSecurityError, "Insecure: can't modify Struct"); + rb_raise(rb_eSecurityError, "Insecure: can't modify %s", rb_obj_classname(s)); } static VALUE diff --git a/time.c b/time.c index b2e3448..91e912b 100644 --- a/time.c +++ b/time.c @@ -1877,7 +1877,7 @@ time_modify(VALUE time) { rb_check_frozen(time); if (!OBJ_UNTRUSTED(time) && rb_safe_level() >= 4) - rb_raise(rb_eSecurityError, "Insecure: can't modify Time"); + rb_raise(rb_eSecurityError, "Insecure: can't modify %s", rb_obj_classname(time)); } static wideval_t diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 49dcdb4..ff9ec32 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'timeout' +require_relative 'envutil' class TestStruct < Test::Unit::TestCase def test_struct @@ -249,4 +250,17 @@ class TestStruct < Test::Unit::TestCase assert !x.eql?(z) } end + + def test_struct_subclass + bugNNNN = '[ruby-dev:NNNN]' + assert_in_out_err([], <<-INPUT, [], /Insecure: can't modify Struct2::S \(SecurityError\)$/, bugNNNN) + Thread.new do + class Struct2 < Struct + end + s = Struct2.new("S", :m).new + $SAFE=4 + s.m=1 + end.join + INPUT + end end diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index aea4c2e..d30ceda 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -3,6 +3,7 @@ require 'rational' require 'delegate' require 'timeout' require 'delegate' +require_relative 'envutil' class TestTime < Test::Unit::TestCase def setup @@ -711,4 +712,17 @@ class TestTime < Test::Unit::TestCase assert_raise(NoMethodError, bug5012) { t1.m } end + + def test_time_subclass + bugNNNN = '[ruby-dev:NNNN]' + assert_in_out_err([], <<-INPUT, [], /Insecure: can't modify Time2 \(SecurityError\)$/, bugNNNN) + Thread.new do + class Time2 < Time + end + t = Time2.now + $SAFE=4 + t.gmtime + end.join + INPUT + end end