Project

General

Profile

Bug #13223 ยป 0001-Fix-segv-in-File.join-when-SEPARATOR-and-Separator-a.patch

tenderlovemaking (Aaron Patterson), 02/17/2017 06:26 PM

View differences:

file.c
return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&path));
}
static VALUE separator;
static VALUE rb_file_join(VALUE ary, VALUE sep);
static VALUE
......
static VALUE
rb_file_s_join(VALUE klass, VALUE args)
{
return rb_file_join(args, separator);
return rb_file_join(args, rb_const_get(rb_cFile, rb_intern("SEPARATOR")));
}
#if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE)
......
rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
rb_define_singleton_method(rb_cFile, "path", rb_file_s_path, 1);
separator = rb_obj_freeze(rb_usascii_str_new2("/"));
VALUE separator = rb_obj_freeze(rb_usascii_str_new_lit("/"));
/* separates directory parts in path */
rb_define_const(rb_cFile, "Separator", separator);
rb_define_const(rb_cFile, "SEPARATOR", separator);
test/ruby/test_file_exhaustive.rb
require "fileutils"
require "tmpdir"
require "socket"
require "envutil"
class TestFileExhaustive < Test::Unit::TestCase
DRIVE = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
......
end
end
def test_file_join_works_after_const_set
EnvUtil.suppress_warning do
File.const_set :SEPARATOR, "/"
File.const_set :Separator, "/"
end
GC.start
assert_equal "a/b", File.join("a", "b")
end
def test_separator_impacts_join
before = File::SEPARATOR
EnvUtil.suppress_warning do
File.const_set :SEPARATOR, "$"
end
assert_equal "a$b", File.join("a", "b")
ensure
EnvUtil.suppress_warning do
File.const_set :SEPARATOR, before
end
end
def test_stat
fn1 = regular_file
hardlinkfile
    (1-1/1)