Makes sure killfilter doesn't raise ValueError
* Fixes bug 926412 * Includes failing test Change-Id: Ie0105ff777575d6dd794ce5b5e08545fb54ecf8b
This commit is contained in:
@@ -100,6 +100,8 @@ class KillFilter(CommandFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def match(self, userargs):
|
def match(self, userargs):
|
||||||
|
if userargs[0] != "kill":
|
||||||
|
return False
|
||||||
args = list(userargs)
|
args = list(userargs)
|
||||||
if len(args) == 3:
|
if len(args) == 3:
|
||||||
signal = args.pop(1)
|
signal = args.pop(1)
|
||||||
@@ -113,13 +115,12 @@ class KillFilter(CommandFilter):
|
|||||||
if '' not in self.args[0]:
|
if '' not in self.args[0]:
|
||||||
# No signal, but list doesn't include empty string
|
# No signal, but list doesn't include empty string
|
||||||
return False
|
return False
|
||||||
pid = int(args[1])
|
|
||||||
try:
|
try:
|
||||||
command = os.readlink("/proc/%d/exe" % pid)
|
command = os.readlink("/proc/%d/exe" % int(args[1]))
|
||||||
if command not in self.args[1]:
|
if command not in self.args[1]:
|
||||||
# Affected executable not in accepted list
|
# Affected executable not in accepted list
|
||||||
return False
|
return False
|
||||||
except:
|
except (ValueError, OSError):
|
||||||
# Incorrect PID
|
# Incorrect PID
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@@ -93,6 +93,16 @@ class RootwrapTestCase(test.TestCase):
|
|||||||
# Providing -9 signal should work
|
# Providing -9 signal should work
|
||||||
self.assertTrue(f.match(usercmd))
|
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):
|
def test_ReadFileFilter(self):
|
||||||
goodfn = '/good/file.name'
|
goodfn = '/good/file.name'
|
||||||
f = filters.ReadFileFilter(goodfn)
|
f = filters.ReadFileFilter(goodfn)
|
||||||
|
Reference in New Issue
Block a user