summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-03-25 01:23:03 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-03-25 01:23:03 +0900
commitc7d668801bd27f8245a15311da4e8e859ba28dec (patch)
tree379fa7f003b05953896c54c44ca10b42f7ad72fc
parent1b3339528c0804aa0e673bd3f15be8b087d17bd8 (diff)
Fixed crash when argument array is modified
-rw-r--r--dir.c2
-rw-r--r--test/ruby/test_dir.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index ea0edf5..5013b9b 100644
--- a/dir.c
+++ b/dir.c
@@ -3096,7 +3096,7 @@ dir_s_glob(int argc, VALUE *argv, VALUE obj)
ary = rb_push_glob(str, base, flags);
}
else {
- VALUE v = ary;
+ VALUE v = rb_ary_replace(rb_ary_tmp_new(0), ary);
ary = dir_globs(RARRAY_LEN(v), RARRAY_CONST_PTR(v), base, flags);
RB_GC_GUARD(v);
}
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index bab2330..13a0c31 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -517,4 +517,16 @@ class TestDir < Test::Unit::TestCase
assert_equal([*"a".."z"], list)
end;
end if defined?(Process::RLIMIT_NOFILE)
+
+ def test_glob_array_with_destructive_element
+ args = Array.new(100, "")
+ pat = Struct.new(:ary).new(args)
+ args.push(pat, *Array.new(100) {"."*40})
+ def pat.to_path
+ ary.clear
+ GC.start
+ ""
+ end
+ assert_empty(Dir.glob(args))
+ end
end