Project

General

Profile

Bug #14485 ยป file-path-taint.patch

jeremyevans0 (Jeremy Evans), 06/20/2019 06:58 PM

View differences:

file.c
459 459
        rb_raise(rb_eIOError, "File is unnamed (TMPFILE?)");
460 460
    }
461 461

  
462
    return rb_obj_taint(rb_str_dup(fptr->pathv));
462
    return rb_str_dup(fptr->pathv);
463 463
}
464 464

  
465 465
static size_t
test/ruby/test_file_exhaustive.rb
187 187
    end
188 188
  end
189 189

  
190
  def test_path_taint
191
    [regular_file, utf8_file].each do |file|
192
      assert_equal(false, File.open(file) {|f| f.path}.tainted?)
193
      assert_equal(true, File.open(file.dup.taint) {|f| f.path}.tainted?)
194
      o = Object.new
195
      class << o; self; end.class_eval do
196
        define_method(:to_path) { file }
197
      end
198
      assert_equal(false, File.open(o) {|f| f.path}.tainted?)
199
      class << o; self; end.class_eval do
200
        define_method(:to_path) { file.dup.taint }
201
      end
202
      assert_equal(true, File.open(o) {|f| f.path}.tainted?)
203
    end
204
  end
205

  
190 206
  def assert_integer(n)
191 207
    assert_kind_of(Integer, n)
192 208
  end