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
4359 4359
    return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&path));
4360 4360
}
4361 4361

  
4362
static VALUE separator;
4363

  
4364 4362
static VALUE rb_file_join(VALUE ary, VALUE sep);
4365 4363

  
4366 4364
static VALUE
......
4461 4459
static VALUE
4462 4460
rb_file_s_join(VALUE klass, VALUE args)
4463 4461
{
4464
    return rb_file_join(args, separator);
4462
    return rb_file_join(args, rb_const_get(rb_cFile, rb_intern("SEPARATOR")));
4465 4463
}
4466 4464

  
4467 4465
#if defined(HAVE_TRUNCATE) || defined(HAVE_CHSIZE)
......
6023 6021
    rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1);
6024 6022
    rb_define_singleton_method(rb_cFile, "path", rb_file_s_path, 1);
6025 6023

  
6026
    separator = rb_obj_freeze(rb_usascii_str_new2("/"));
6024
    VALUE separator = rb_obj_freeze(rb_usascii_str_new_lit("/"));
6027 6025
    /* separates directory parts in path */
6028 6026
    rb_define_const(rb_cFile, "Separator", separator);
6029 6027
    rb_define_const(rb_cFile, "SEPARATOR", separator);
test/ruby/test_file_exhaustive.rb
3 3
require "fileutils"
4 4
require "tmpdir"
5 5
require "socket"
6
require "envutil"
6 7

  
7 8
class TestFileExhaustive < Test::Unit::TestCase
8 9
  DRIVE = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
......
199 200
    end
200 201
  end
201 202

  
203
  def test_file_join_works_after_const_set
204
    EnvUtil.suppress_warning do
205
      File.const_set :SEPARATOR, "/"
206
      File.const_set :Separator, "/"
207
    end
208

  
209
    GC.start
210
    assert_equal "a/b", File.join("a", "b")
211
  end
212

  
213
  def test_separator_impacts_join
214
    before = File::SEPARATOR
215
    EnvUtil.suppress_warning do
216
      File.const_set :SEPARATOR, "$"
217
    end
218

  
219
    assert_equal "a$b", File.join("a", "b")
220

  
221
  ensure
222
    EnvUtil.suppress_warning do
223
      File.const_set :SEPARATOR, before
224
    end
225
  end
226

  
202 227
  def test_stat
203 228
    fn1 = regular_file
204 229
    hardlinkfile
205
-