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
|
|
|
|
@dir = tmp("CVE-2018-6914")
|
|
|
|
Dir.mkdir(@dir)
|
|
|
|
touch "#{@dir}/bar"
|
|
|
|
|
|
|
|
@traversal_path = Array.new(@dir.count('/'), '..').join('/') + @dir + '/'
|
|
|
|
@traversal_path.delete!(':') if platform_is(:windows)
|
|
|
|
|
|
|
|
@tempfile = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
|
|
|
@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-02-21 10:38:59 -05:00
|
|
|
expect = Dir.glob(@traversal_path + '*').size
|
|
|
|
@tempfile = Tempfile.open([@traversal_path, 'foo'])
|
|
|
|
actual = Dir.glob(@traversal_path + '*').size
|
|
|
|
actual.should == expect
|
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-02-21 10:38:59 -05:00
|
|
|
expect = Dir.glob(@traversal_path + '*').size
|
|
|
|
@tempfile = Tempfile.new(@traversal_path + 'foo')
|
|
|
|
actual = Dir.glob(@traversal_path + '*').size
|
|
|
|
actual.should == expect
|
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-02-21 10:38:59 -05:00
|
|
|
expect = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
Tempfile.create(@traversal_path + 'foo') do
|
2019-02-21 10:38:59 -05:00
|
|
|
actual = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
actual.should == expect
|
|
|
|
end
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Dir.mktmpdir by deleting separators" do
|
2019-02-21 10:38:59 -05:00
|
|
|
expect = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
Dir.mktmpdir(@traversal_path + 'foo') do
|
2019-02-21 10:38:59 -05:00
|
|
|
actual = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
actual.should == expect
|
|
|
|
end
|
2018-06-13 17:41:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "Dir.mktmpdir with an array by deleting separators" do
|
2019-02-21 10:38:59 -05:00
|
|
|
expect = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
Dir.mktmpdir([@traversal_path, 'foo']) do
|
2019-02-21 10:38:59 -05:00
|
|
|
actual = Dir.glob(@traversal_path + '*').size
|
2018-07-11 04:33:32 -04:00
|
|
|
actual.should == expect
|
|
|
|
end
|
2018-04-28 15:50:06 -04:00
|
|
|
end
|
|
|
|
end
|