Skip to content

Commit db83e48

Browse files
committed
Check for nil before closing Uniquefile
On Windows, if squelch was false and Uniquefile.new raised, then we attempted to close a nil stdout. This scenario can occur if TEMP or similar environment variable is defined but refers to a non-existent directory. 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 db83e48

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-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

+10
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,16 @@ 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(
841+
Errno::ENOENT,
842+
'No such file or directory @ rb_file_s_stat - C:\Users\ADMINI~1\AppData\Local\Temp\doesnotexist')
843+
expect {
844+
Puppet::Util::Execution.execute('test command')
845+
}.to raise_error(Errno::ENOENT, 'No such file or directory @ rb_file_s_stat - C:\Users\ADMINI~1\AppData\Local\Temp\doesnotexist')
846+
end
837847
end
838848

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

0 commit comments

Comments
 (0)