Skip to content

Commit

Permalink
Merge pull request #182 from ringods/master
Browse files Browse the repository at this point in the history
Sanitize the environment before spawning
  • Loading branch information
carlossg committed Mar 12, 2014
2 parents 299fe34 + dd80dca commit 56cfc57
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/librarian/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@

status = nil
out = nil
err = nil
error = nil

begin
Open3.popen3('puppet --version') {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
out = stdout.read
status = wait_thr.value # Process::Status object returned.
}
if RUBY_VERSION < '1.9'
# Ruby 1.8.x backport of popen3 doesn't allow the 'env' hash argument
# Not sanitizing the environment for the moment.
Open3.popen3('puppet --version') {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
out = stdout.read
err = stderr.read
status = wait_thr.value # Process::Status object returned.
}
else
Open3.popen3({"GEM_PATH"=> nil},'puppet --version') {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
out = stdout.read
err = stderr.read
status = wait_thr.value # Process::Status object returned.
}
end
rescue => e
error = e
end
Expand All @@ -22,6 +35,7 @@
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc).
#{out.nil? or out.empty? ? "puppet --version returned #{status.exitstatus}" : out}
#{error.message unless error.nil?}
#{err unless err.nil?}
EOF
exit 1
end
Expand Down

0 comments on commit 56cfc57

Please sign in to comment.