Avoid maximal recursion error

This commit is contained in:
Gerard Wagener 2010-01-18 09:39:24 +01:00
parent ddc4d50b77
commit f8290a30db

View file

@ -119,7 +119,9 @@ class ProcessTrees:
pass
def searchTree(self,pid,ppid):
#Make sure that pid is different from ppid -> to avoid recursion error
if pid == ppid:
# Avoid recursion error
return 0
self.foundUser = 0
self.__searchTree(pid,ppid)
#If the process belongs to the system remove it, to free up memory
@ -190,6 +192,14 @@ class TestProcessTree(unittest.TestCase):
self.assertEqual(ret,0)
self.assertEqual(len(x.processList.keys()),1)
def testRecurionErrorBreak(self):
#FIXME can an attacker create a process having its own parent?
x = ProcessTrees()
x.addUser(123)
x.searchTree(123,222)
ret = x.searchTree(222,222)
self.assertEqual(ret,0)
if __name__ == '__main__':
unittest.main()