File ruby-1.8.7_safe_level_bypass.patch of Package ruby19.openSUSE_12.2_Update
Index: error.c
===================================================================
--- error.c.orig 2012-02-25 13:32:19.000000000 +0100
+++ error.c 2012-10-26 13:03:11.760708214 +0200
@@ -569,7 +569,6 @@ exc_to_s(VALUE exc)
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
r = rb_String(mesg);
- OBJ_INFECT(r, exc);
return r;
}
@@ -853,11 +852,7 @@ name_err_to_s(VALUE exc)
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
StringValue(str);
- if (str != mesg) {
- rb_iv_set(exc, "mesg", mesg = str);
- }
- OBJ_INFECT(mesg, exc);
- return mesg;
+ return str;
}
/*
@@ -988,7 +983,6 @@ name_err_mesg_to_str(VALUE obj)
args[2] = d;
mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args);
}
- OBJ_INFECT(mesg, obj);
return mesg;
}
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb.orig 2012-02-08 01:44:05.000000000 +0100
+++ test/ruby/test_exception.rb 2012-10-26 13:03:11.761708215 +0200
@@ -333,4 +333,54 @@ end.join
load(t.path)
end
end
+
+ def test_to_s_taintness_propagation
+ for exc in [Exception, NameError]
+ m = "abcdefg"
+ e = exc.new(m)
+ e.taint
+ s = e.to_s
+ assert_equal(false, m.tainted?,
+ "#{exc}#to_s should not propagate taintness")
+ assert_equal(false, s.tainted?,
+ "#{exc}#to_s should not propagate taintness")
+ end
+
+ o = Object.new
+ def o.to_str
+ "foo"
+ end
+ o.taint
+ e = NameError.new(o)
+ s = e.to_s
+ 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
+ o.singleton_class.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