mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[ruby/pathname] Fix segfault of Pathname#split
Fix segmentation fault of Pathname#split when File.split returns non array value [Bug #17755]e29b49e3b11db7479a74
This commit is contained in:
		
							parent
							
								
									447e095413
								
							
						
					
					
						commit
						9af57eeed6
					
				
					 2 changed files with 16 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -834,7 +834,7 @@ path_split(VALUE self)
 | 
			
		|||
    VALUE str = get_strpath(self);
 | 
			
		||||
    VALUE ary, dirname, basename;
 | 
			
		||||
    ary = rb_funcall(rb_cFile, id_split, 1, str);
 | 
			
		||||
    ary = rb_check_array_type(ary);
 | 
			
		||||
    Check_Type(ary, T_ARRAY);
 | 
			
		||||
    dirname = rb_ary_entry(ary, 0);
 | 
			
		||||
    basename = rb_ary_entry(ary, 1);
 | 
			
		||||
    dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1067,6 +1067,21 @@ class TestPathname < Test::Unit::TestCase
 | 
			
		|||
 | 
			
		||||
  def test_split
 | 
			
		||||
    assert_equal([Pathname("dirname"), Pathname("basename")], Pathname("dirname/basename").split)
 | 
			
		||||
 | 
			
		||||
    assert_separately([], <<-'end;')
 | 
			
		||||
      require 'pathname'
 | 
			
		||||
 | 
			
		||||
      mod = Module.new do
 | 
			
		||||
        def split(_arg)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      File.singleton_class.prepend(mod)
 | 
			
		||||
 | 
			
		||||
      assert_raise(TypeError) do
 | 
			
		||||
        Pathname('/').split
 | 
			
		||||
      end
 | 
			
		||||
    end;
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_blockdev?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue