Skip to content

Commit 7296cce

Browse files
committed
Check for nil before closing Uniquefile
On Windows, we by default assign stdout for the child process to a file: stdout = Puppet::FileSystem::Uniquefile.new('puppet') However, if TMPDIR, TEMP or TMP env vars refer to a non-existent directory, then `Uniquefile.new` will raise, leaving `stdout` set to nil, so the later call to `stdout.close` raised NoMethodError. So check for nil before closing. We don't have this issue on posix, because it uses an IO pipe instead of Uniquefile. Fixes #9385
1 parent a423af8 commit 7296cce

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/puppet/util/execution.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def self.execute(command, options = NoOptionsSpecified)
323323
unless options[:squelch]
324324
# if we opened a pipe, we need to clean it up.
325325
reader.close if reader
326-
stdout.close! if Puppet::Util::Platform.windows?
326+
stdout.close! if stdout && Puppet::Util::Platform.windows?
327327
end
328328
end
329329

spec/unit/util/execution_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,15 @@ def expect_cwd_to_be(cwd)
834834

835835
Puppet::Util::Execution.execute('test command')
836836
end
837+
838+
it "should raise if it fails to create a Uniquefile for stdout" do
839+
allow(Puppet::FileSystem::Uniquefile).to receive(:new)
840+
.and_raise(Errno::ENOENT, 'C:\Users\ADMINI~1\AppData\Local\Temp\doesnotexist')
841+
842+
expect {
843+
Puppet::Util::Execution.execute('test command')
844+
}.to raise_error(Errno::ENOENT, 'No such file or directory - C:\Users\ADMINI~1\AppData\Local\Temp\doesnotexist')
845+
end
837846
end
838847

839848
it "should raise an error if failonfail is true and the child failed" do

0 commit comments

Comments
 (0)