Skip to content

Commit

Permalink
Makes sure killfilter doesn't raise ValueError
Browse files Browse the repository at this point in the history
 * Fixes bug 926412
 * Includes failing test

Change-Id: Ie0105ff777575d6dd794ce5b5e08545fb54ecf8b
  • Loading branch information
vishvananda committed Feb 8, 2012
1 parent b0a708f commit 4ce6645
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nova/rootwrap/filters.py
Expand Up @@ -100,6 +100,8 @@ class KillFilter(CommandFilter):
"""

def match(self, userargs):
if userargs[0] != "kill":
return False
args = list(userargs)
if len(args) == 3:
signal = args.pop(1)
Expand All @@ -113,13 +115,12 @@ def match(self, userargs):
if '' not in self.args[0]:
# No signal, but list doesn't include empty string
return False
pid = int(args[1])
try:
command = os.readlink("/proc/%d/exe" % pid)
command = os.readlink("/proc/%d/exe" % int(args[1]))
if command not in self.args[1]:
# Affected executable not in accepted list
return False
except:
except (ValueError, OSError):
# Incorrect PID
return False
return True
Expand Down
10 changes: 10 additions & 0 deletions nova/tests/test_nova_rootwrap.py
Expand Up @@ -93,6 +93,16 @@ def test_KillFilter(self):
# Providing -9 signal should work
self.assertTrue(f.match(usercmd))

def test_KillFilter_no_raise(self):
"""Makes sure ValueError from bug 926412 is gone"""
f = filters.KillFilter("/bin/kill", "root", [""])
# Providing anything other than kill should be False
usercmd = ['notkill', 999999]
self.assertFalse(f.match(usercmd))
# Providing something that is not a pid should be False
usercmd = ['kill', 'notapid']
self.assertFalse(f.match(usercmd))

def test_ReadFileFilter(self):
goodfn = '/good/file.name'
f = filters.ReadFileFilter(goodfn)
Expand Down

0 comments on commit 4ce6645

Please sign in to comment.