From b887c7c20ab81b50ed7cb8c7db3218c443985d6b Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 3 Dec 2015 07:02:19 +0000 Subject: [PATCH] string.c: should not taint fstring * string.c (rb_obj_as_string): fstring should not be infected. TODO: other frozen strings also may not be. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 4 +++- test/ruby/test_object.rb | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3066d279e9..4a5734b2b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 3 16:02:17 2015 Nobuyoshi Nakada + + * string.c (rb_obj_as_string): fstring should not be infected. + TODO: other frozen strings also may not be. + Thu Dec 3 15:39:21 2015 SHIBATA Hiroshi * lib/scanf.rb: fixed double words typo. diff --git a/string.c b/string.c index d1a051b6dd..4cb62375da 100644 --- a/string.c +++ b/string.c @@ -1247,7 +1247,9 @@ rb_obj_as_string(VALUE obj) str = rb_funcall(obj, idTo_s, 0); if (!RB_TYPE_P(str, T_STRING)) return rb_any_to_s(obj); - OBJ_INFECT(str, obj); + if (!FL_SET(str, RSTRING_FSTR) && FL_ABLE(obj)) + /* fstring must not be tainted, at least */ + OBJ_INFECT_RAW(str, obj); return str; } diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index a3c71d605c..27f3bd18ce 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -755,6 +755,15 @@ class TestObject < Test::Unit::TestCase end EOS assert_match(/\bToS\u{3042}:/, x) + + name = "X".freeze + x = Object.new.taint + class<