2018-04-28 15:50:06 -04:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
|
|
|
require 'tempfile'
|
2019-02-21 10:38:59 -05:00
|
|
|
require 'tmpdir'
|
2018-04-28 15:50:06 -04:00
|
|
|
|
2018-06-13 17:41:45 -04:00
|
|
|
describe "CVE-2018-6914 is resisted by" do
|
2019-02-21 10:38:59 -05:00
|
|
|
before :each do
|
2019-10-29 09:39:30 -04:00
|
|
|
@tmpdir = ENV['TMPDIR']
|
2019-02-21 10:38:59 -05:00
|
|
|
@dir = tmp("CVE-2018-6914")
|
2019-11-09 08:40:14 -05:00
|
|
|
Dir.mkdir(@dir, 0700)
|
2019-10-29 09:39:30 -04:00
|
|
|
ENV['TMPDIR'] = @dir
|
|
|
|
@dir << '/'
|
2019-02-21 10:38:59 -05:00
|
|
|
|
|
|
|
@tempfile = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
2019-10-29 09:39:30 -04:00
|
|
|
ENV['TMPDIR'] = @tmpdir
|
2019-02-21 10:38:59 -05:00
|
|
|
@tempfile.close! if @tempfile
|
|
|
|
rm_r @dir
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
2018-04-28 15:50:06 -04:00
|
|
|
|
2018-06-13 17:41:45 -04:00
|
|
|
it "Tempfile.open by deleting separators" do
|
2019-10-29 09:39:30 -04:00
|
|
|
@tempfile = Tempfile.open(['../', 'foo'])
|
|
|
|
actual = @tempfile.path
|
|
|
|
File.absolute_path(actual).should.start_with?(@dir)
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
2018-04-28 15:50:06 -04:00
|
|
|
|
2018-06-13 17:41:45 -04:00
|
|
|
it "Tempfile.new by deleting separators" do
|
2019-10-29 09:39:30 -04:00
|
|
|
@tempfile = Tempfile.new('../foo')
|
|
|
|
actual = @tempfile.path
|
|
|
|
File.absolute_path(actual).should.start_with?(@dir)
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
2018-04-28 15:50:06 -04:00
|
|
|
|
2018-06-13 17:41:45 -04:00
|
|
|
it "Tempfile.create by deleting separators" do
|
2019-10-29 09:39:30 -04:00
|
|
|
actual = Tempfile.create('../foo') do |t|
|
|
|
|
t.path
|
2018-07-11 04:33:32 -04:00
|
|
|
end
|
2019-10-29 09:39:30 -04:00
|
|
|
File.absolute_path(actual).should.start_with?(@dir)
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Dir.mktmpdir by deleting separators" do
|
2019-10-29 09:39:30 -04:00
|
|
|
actual = Dir.mktmpdir('../foo') do |path|
|
|
|
|
path
|
2018-07-11 04:33:32 -04:00
|
|
|
end
|
2019-10-29 09:39:30 -04:00
|
|
|
File.absolute_path(actual).should.start_with?(@dir)
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Dir.mktmpdir with an array by deleting separators" do
|
2019-10-29 09:39:30 -04:00
|
|
|
actual = Dir.mktmpdir(['../', 'foo']) do |path|
|
|
|
|
path
|
2018-07-11 04:33:32 -04:00
|
|
|
end
|
2019-10-29 09:39:30 -04:00
|
|
|
File.absolute_path(actual).should.start_with?(@dir)
|
2018-04-28 15:50:06 -04:00
|
|
|
end
|
|
|
|
end
|