зеркало из https://github.com/github/ruby.git
adds a test case for r21955 and r21917.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
416ab0f7be
Коммит
1d551324bb
|
@ -195,4 +195,50 @@ class TestRequire < Test::Unit::TestCase
|
|||
|
||||
assert_raise(ArgumentError) { at_exit }
|
||||
end
|
||||
|
||||
def test_tainted_loadpath
|
||||
t = Tempfile.new(["test_ruby_test_require", ".rb"])
|
||||
abs_dir, file = File.dirname(t.path), File.basename(t.path)
|
||||
abs_dir = File.expand_path(abs_dir).untaint
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
$SAFE = 1
|
||||
begin
|
||||
require "#{ file }"
|
||||
rescue SecurityError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
$SAFE = 1
|
||||
require "#{ t.path }"
|
||||
p :ok
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir << 'elsewhere'.taint
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
INPUT
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче