Fixes #10289: Create proper tmp dir for ControlPath

Prior to this commit, when creating the ControlPath tmp dir for
socket path, Vagrant would simply rely on `rand(1000)` for making unique
dirs for rsyncing files which could result in collisions. This commit
updates that be properly using `Dir.mktmpdir` with a `vagrant-rsync-`
prefix.
This commit is contained in:
Brian Cain 2018-10-11 09:47:54 -07:00
parent 56aa5860cb
commit cb0bd89ae1
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 15 additions and 1 deletions

View File

@ -81,7 +81,7 @@ module VagrantPlugins
# too long for unix domain sockets. # too long for unix domain sockets.
control_options = "" control_options = ""
unless Vagrant::Util::Platform.windows? unless Vagrant::Util::Platform.windows?
controlpath = File.join(Dir.tmpdir, "ssh.#{rand(1000)}") controlpath = Dir.mktmpdir("vagrant-rsync-")
control_options = "-o ControlMaster=auto -o ControlPath=#{controlpath} -o ControlPersist=10m " control_options = "-o ControlMaster=auto -o ControlPath=#{controlpath} -o ControlPersist=10m "
end end

View File

@ -212,6 +212,20 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
subject.rsync_single(machine, ssh_info, opts) subject.rsync_single(machine, ssh_info, opts)
end end
end end
context "control sockets" do
it "creates a tmp dir" do
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
allow(Dir).to receive(:mktmpdir).with("vagrant-rsync-").
and_return("/tmp/vagrant-rsync-12345")
expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args|
expect(args[9]).to include("ControlPath=/tmp/vagrant-rsync-12345")
}.and_return(result)
subject.rsync_single(machine, ssh_info, opts)
end
end
end end
describe "#rsync_single with custom ssh_info" do describe "#rsync_single with custom ssh_info" do