Skip to content

Commit d6adc68

Browse files
committed
lib/shell/command-processor.rb (Shell#[]): prevent unknown command
`FileTest.send(command, ...)` allows to call not only FileTest-related methods but also any method that belongs to Kernel, Object, etc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 8d5d5d5 commit d6adc68

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/shell/command-processor.rb

+3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ def test(command, file1, file2=nil)
180180
top_level_test(command, file1)
181181
end
182182
else
183+
unless FileTest.methods(false).include?(command.to_sym)
184+
raise "unsupported command: #{ command }"
185+
end
183186
if file2
184187
FileTest.send(command, file1, file2)
185188
else

test/shell/test_command_processor.rb

+18
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ def test_system_directory
6868
Dir.rmdir(path)
6969
end
7070

71+
def test_test
72+
name = "foo#{exeext}"
73+
path = File.join(@tmpdir, name)
74+
open(path, "w", 0644) {}
75+
76+
assert_equal(true, @shell[?e, path])
77+
assert_equal(true, @shell[:e, path])
78+
assert_equal(true, @shell["e", path])
79+
assert_equal(true, @shell[:exist?, path])
80+
assert_equal(true, @shell["exist?", path])
81+
assert_raise_with_message(RuntimeError, /unsupported command/) do
82+
assert_equal(true, @shell[:instance_eval, path])
83+
end
84+
ensure
85+
Process.waitall
86+
File.unlink(path)
87+
end
88+
7189
def test_option_type
7290
name = 'foo.cmd'
7391
path = File.join(@tmpdir, name)

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.6.5"
22
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
3-
#define RUBY_PATCHLEVEL 113
3+
#define RUBY_PATCHLEVEL 114
44

55
#define RUBY_RELEASE_YEAR 2019
66
#define RUBY_RELEASE_MONTH 10

0 commit comments

Comments
 (0)