Skip to content

Commit bfcd0e2

Browse files
Merge pull request #296 from aleksei-burlakov/security-fixes
Dev: proof code from injections
2 parents a996420 + 578145b commit bfcd0e2

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

hawk/app/lib/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def popen3(user, *cmd)
4343
# RORSCAN_INL: cmd always has > 1 elem, so safe from shell injection
4444
exec(*cmd)
4545
else
46-
command = ['su', '-', user, 'sh', '-c', "#{cmd.join(" ")}"]
46+
command = ['su', '-', user.shellescape, 'sh', '-c', cmd.shelljoin]
4747
exec(*command)
4848
end
4949
}

hawk/app/models/crm_config.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def persisted?
4949

5050
class << self
5151
def get_parameters_from(crm_config, cmd)
52-
#todo: this doesn't work with safe_x. research why.
53-
REXML::Document.new(%x[#{cmd} 2>/dev/null]).tap do |xml|
52+
REXML::Document.new(Util.safe_x(*cmd)).tap do |xml|
5453
return unless xml.root
5554

5655
xml.elements.each("//parameter") do |param|
@@ -108,7 +107,7 @@ def mapping
108107
# The crm_attribute --list-options is only available since pacemaker 2.1.8
109108
# Let's try crm_attribute first, and if fails,
110109
# then do as before (with pengine, crmd, ..., pacemaker-based)
111-
cmd = "crm_attribute --list-options=cluster --all --output-as=xml"
110+
cmd = ["crm_attribute", "--list-options=cluster", "--all", "--output-as=xml"]
112111
get_parameters_from(crm_config, cmd)
113112
if crm_config.empty?
114113
[
@@ -121,7 +120,7 @@ def mapping
121120
].each do |binary|
122121
path = "#{Rails.configuration.x.crm_daemon_dir}/#{binary}"
123122
next unless File.executable? path
124-
cmd = "#{path} metadata"
123+
cmd = ["#{path}", "metadata"]
125124
get_parameters_from(crm_config, cmd)
126125
end
127126
end

0 commit comments

Comments
 (0)