Project

General

Profile

Bug #11386 » 0002-tests-for-fstring-taintedness.patch

nobu (Nobuyoshi Nakada), 07/22/2015 11:23 PM

View differences:

ext/-test-/string/fstring.c
#include "ruby.h"
VALUE rb_fstring(VALUE str);
VALUE
bug_s_fstring(VALUE self, VALUE str)
{
return rb_fstring(str);
}
void
Init_fstring(VALUE klass)
{
rb_define_singleton_method(klass, "fstring", bug_s_fstring, 1);
}
string.c
}
}
RUBY_FUNC_EXPORTED
VALUE
rb_fstring(VALUE str)
{
test/-ext-/string/test_fstring.rb
require 'test/unit'
require '-test-/string'
class Test_String_Fstring < Test::Unit::TestCase
def test_taint_shared_string
str = __method__.to_s.dup
str.taint
fstr = Bug::String.fstring(str)
assert_predicate(str, :tainted?)
assert_predicate(fstr, :tainted?)
end
def test_taint_normal_string
str = __method__.to_s.capitalize
str.taint
fstr = Bug::String.fstring(str)
assert_predicate(str, :tainted?)
assert_predicate(fstr, :tainted?)
end
def test_taint_registered_tainted
str = __method__.to_s.capitalize
str.taint
fstr = Bug::String.fstring(str)
assert_predicate(str, :tainted?)
assert_predicate(fstr, :tainted?)
str = __method__.to_s.capitalize
fstr = Bug::String.fstring(str)
assert_not_predicate(str, :tainted?)
assert_not_predicate(fstr, :tainted?)
end
def test_taint_registered_untainted
str = __method__.to_s.capitalize
fstr = Bug::String.fstring(str)
assert_not_predicate(str, :tainted?)
assert_not_predicate(fstr, :tainted?)
str = __method__.to_s.capitalize
str.taint
fstr = Bug::String.fstring(str)
assert_predicate(str, :tainted?)
assert_predicate(fstr, :tainted?)
end
end
(2-2/3)