mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix TOCTTOU and avoid to read existing unreadable file
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dff3d5dc69
commit
6d14c47c20
2 changed files with 18 additions and 2 deletions
|
@ -111,8 +111,11 @@ EOF
|
||||||
file, pos = @binding.eval('[__FILE__, __LINE__]')
|
file, pos = @binding.eval('[__FILE__, __LINE__]')
|
||||||
|
|
||||||
unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
|
unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
|
||||||
return unless File.exist?(file)
|
begin
|
||||||
lines = File.readlines(file)
|
lines = File.readlines(file)
|
||||||
|
rescue SystemCallError
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
pos -= 1
|
pos -= 1
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,19 @@ module TestIRB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_code_around_binding_with_existing_unreadable_file
|
||||||
|
Tempfile.create do |f|
|
||||||
|
code = "IRB::WorkSpace.new(binding)\n"
|
||||||
|
f.print(code)
|
||||||
|
f.close
|
||||||
|
|
||||||
|
File.chmod(0, f.path)
|
||||||
|
|
||||||
|
workspace = eval(code, binding, f.path)
|
||||||
|
assert_equal(nil, workspace.code_around_binding)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_code_around_binding_with_script_lines__
|
def test_code_around_binding_with_script_lines__
|
||||||
with_script_lines do |script_lines|
|
with_script_lines do |script_lines|
|
||||||
Tempfile.create do |f|
|
Tempfile.create do |f|
|
||||||
|
|
Loading…
Reference in a new issue