1
0
Fork 0
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]

https://github.com/ruby/pathname/commit/e29b49e3b1
https://github.com/ruby/pathname/commit/1db7479a74
This commit is contained in:
Kenichi Kamiya 2021-03-27 14:45:10 +09:00 committed by Nobuyoshi Nakada
parent 447e095413
commit 9af57eeed6
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 16 additions and 1 deletions

View file

@ -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));

View file

@ -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?