diff options
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_exception.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index c5f409117c..434838f614 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -204,6 +204,34 @@ class TestException < Test::Unit::TestCase o.taint e = NameError.new(o) s = e.to_s - assert_equal(true, s.tainted?) + assert_equal(false, s.tainted?) + end + + def test_exception_to_s_should_not_propagate_untrustedness + favorite_lang = "Ruby" + + for exc in [Exception, NameError] + assert_raise(SecurityError) do + lambda { + $SAFE = 4 + exc.new(favorite_lang).to_s + favorite_lang.replace("Python") + }.call + end + end + + assert_raise(SecurityError) do + lambda { + $SAFE = 4 + o = Object.new + (class << o; self; end).send(:define_method, :to_str) { + favorite_lang + } + NameError.new(o).to_s + favorite_lang.replace("Python") + }.call + end + + assert_equal("Ruby", favorite_lang) end end |