Skip to content

Commit f169986

Browse files
authored
Merge pull request #4 from kachick/fix-segv-when-file-split-returns-non-array
Fix segmentation fault of `Pathname#split` when `File.split` returns non array value [Bug #17755]
2 parents a71f7d8 + 1db7479 commit f169986

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/pathname/pathname.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ path_split(VALUE self)
834834
VALUE str = get_strpath(self);
835835
VALUE ary, dirname, basename;
836836
ary = rb_funcall(rb_cFile, id_split, 1, str);
837-
ary = rb_check_array_type(ary);
837+
Check_Type(ary, T_ARRAY);
838838
dirname = rb_ary_entry(ary, 0);
839839
basename = rb_ary_entry(ary, 1);
840840
dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));

test/pathname/test_pathname.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,21 @@ def test_expand_path
10671067

10681068
def test_split
10691069
assert_equal([Pathname("dirname"), Pathname("basename")], Pathname("dirname/basename").split)
1070+
1071+
assert_separately([], <<-'end;')
1072+
require 'pathname'
1073+
1074+
mod = Module.new do
1075+
def split(_arg)
1076+
end
1077+
end
1078+
1079+
File.singleton_class.prepend(mod)
1080+
1081+
assert_raise(TypeError) do
1082+
Pathname('/').split
1083+
end
1084+
end;
10701085
end
10711086

10721087
def test_blockdev?

0 commit comments

Comments
 (0)