summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 08:55:07 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 08:55:07 +0000
commit2c791e967aa3bdc0484c301336a006b4a6381fe5 (patch)
tree88fcc522784870895e93666e874ceef43c93794c
parent4928543d617e584c847b151c683ba72a0075b07d (diff)
Merge r37148 from ruby_1_8_7.
* error.c (name_err_to_s): we need not infect msg. * test/ruby/test_exception.rb (TestException#test_exception_to_s_should_not_propagate_untrustedness): test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@37220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--error.c3
-rw-r--r--test/ruby/test_exception.rb30
3 files changed, 35 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 956d9a0da2..e3db3bd06d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Oct 16 17:00:36 2012 Akinori MUSHA <knu@iDaemons.org>
+
+ * error.c (name_err_to_s): we need not infect msg.
+
+ * test/ruby/test_exception.rb (TestException#test_exception_to_s_should_not_propagate_untrustedness): test for it.
+
Tue Oct 16 16:51:08 2012 Akinori MUSHA <knu@iDaemons.org>
* ext/bigdecimal/bigdecimal.c (VpMemAlloc): Fixes a bug reported
diff --git a/error.c b/error.c
index b55a68daca..2afb38dc39 100644
--- a/error.c
+++ b/error.c
@@ -665,9 +665,6 @@ name_err_to_s(exc)
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
StringValue(str);
- if (str != mesg) {
- OBJ_INFECT(str, mesg);
- }
return str;
}
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