Escape some bash special characters being passed to bash via system. (#6543)

This commit is contained in:
Satadru Pramanik
2021-12-30 11:30:14 -05:00
committed by GitHub
parent 9fec3a7828
commit d9a41ab108

View File

@@ -164,13 +164,19 @@ class Package
{ exception: true }
end
# add -j arg to build commands
# Add -j arg to build commands.
cmd_args.sub(/\b(?<=make)(?=\b)/, " -j#{CREW_NPROC}") unless cmd_args =~ /-j\s*\d+/
# Escape special bash characters.
cmd_args.gsub!('"','\\\\"')
cmd_args.gsub!('$','\\\\$')
cmd_args.gsub!('`','\\\\`')
begin
# use bash instead of /bin/sh
@system_args = ''
[@system_args, "bash -e -c \"#{cmd_args}\""].reduce(&:concat)
# Uncomment following line for debugging.
# puts @system_args.orange
Kernel.system(@system_args, system_options)
rescue => e
exitstatus = $?.exitstatus