[前][次][番号順一覧][スレッド一覧]

ruby-changes:65673

From: Kenichi <ko1@a...>
Date: Sun, 28 Mar 2021 14:06:06 +0900 (JST)
Subject: [ruby-changes:65673] 9af57eeed6 (master): [ruby/pathname] Fix segfault of Pathname#split

https://git.ruby-lang.org/ruby.git/commit/?id=9af57eeed6

From 9af57eeed61ad53c0a2a92a93a6a6e40704cd6ae Mon Sep 17 00:00:00 2001
From: Kenichi Kamiya <kachick1@g...>
Date: Sat, 27 Mar 2021 14:45:10 +0900
Subject: [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
---
 ext/pathname/pathname.c        |  2 +-
 test/pathname/test_pathname.rb | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 55577d7..1d4ed28 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -834,7 +834,7 @@ path_split(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L834
     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));
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 46a04ee..8a0f3cb 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1067,6 +1067,21 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L1067
 
   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?
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]