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
1
#include "ruby.h"
2

  
3
VALUE rb_fstring(VALUE str);
4

  
5
VALUE
6
bug_s_fstring(VALUE self, VALUE str)
7
{
8
    return rb_fstring(str);
9
}
10

  
11
void
12
Init_fstring(VALUE klass)
13
{
14
    rb_define_singleton_method(klass, "fstring", bug_s_fstring, 1);
15
}
string.c
260 260
    }
261 261
}
262 262

  
263
RUBY_FUNC_EXPORTED
263 264
VALUE
264 265
rb_fstring(VALUE str)
265 266
{
test/-ext-/string/test_fstring.rb
1
require 'test/unit'
2
require '-test-/string'
3

  
4
class Test_String_Fstring < Test::Unit::TestCase
5
  def test_taint_shared_string
6
    str = __method__.to_s.dup
7
    str.taint
8
    fstr = Bug::String.fstring(str)
9
    assert_predicate(str, :tainted?)
10
    assert_predicate(fstr, :tainted?)
11
  end
12

  
13
  def test_taint_normal_string
14
    str = __method__.to_s.capitalize
15
    str.taint
16
    fstr = Bug::String.fstring(str)
17
    assert_predicate(str, :tainted?)
18
    assert_predicate(fstr, :tainted?)
19
  end
20

  
21
  def test_taint_registered_tainted
22
    str = __method__.to_s.capitalize
23
    str.taint
24
    fstr = Bug::String.fstring(str)
25
    assert_predicate(str, :tainted?)
26
    assert_predicate(fstr, :tainted?)
27

  
28
    str = __method__.to_s.capitalize
29
    fstr = Bug::String.fstring(str)
30
    assert_not_predicate(str, :tainted?)
31
    assert_not_predicate(fstr, :tainted?)
32
  end
33

  
34
  def test_taint_registered_untainted
35
    str = __method__.to_s.capitalize
36
    fstr = Bug::String.fstring(str)
37
    assert_not_predicate(str, :tainted?)
38
    assert_not_predicate(fstr, :tainted?)
39

  
40
    str = __method__.to_s.capitalize
41
    str.taint
42
    fstr = Bug::String.fstring(str)
43
    assert_predicate(str, :tainted?)
44
    assert_predicate(fstr, :tainted?)
45
  end
46
end