Skip to content

Commit

Permalink
Merge pull request #7774 from techhat/cmdinjection
Browse files Browse the repository at this point in the history
Fix command injection vulnerability in disk.usage
  • Loading branch information
thatch45 committed Oct 12, 2013
2 parents b89fa91 + 7f190ff commit 6d8ef68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion salt/modules/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Import salt libs
import salt.utils

from salt.exceptions import CommandExecutionError

log = logging.getLogger(__name__)


Expand All @@ -31,14 +33,21 @@ def usage(args=None):
salt '*' disk.usage
'''
flags = ''
allowed = ('a', 'B', 'h', 'H', 'i', 'k', 'l', 'P', 't', 'T', 'x', 'v')
for flag in args:
if flag in allowed:
flags += flag
else:
raise CommandExecutionError('Invalid flag passed to disk.usage')
if __grains__['kernel'] == 'Linux':
cmd = 'df -P'
elif __grains__['kernel'] == 'OpenBSD':
cmd = 'df -kP'
else:
cmd = 'df'
if args:
cmd = cmd + ' -' + args
cmd += ' -{0}'.format(flags)
ret = {}
out = __salt__['cmd.run'](cmd).splitlines()
for line in out:
Expand Down

0 comments on commit 6d8ef68

Please sign in to comment.