[pyatspi2] findAncestor: bail after a reasonable number of tries



commit 637b8b14d07b0277aad7f9182609a87fb28458f0
Author: Mike Gorse <mgorse suse com>
Date:   Wed Mar 10 17:41:22 2021 -0600

    findAncestor: bail after a reasonable number of tries
    
    Similar to the change for getPath, add a safeguard here so that we don't
    loop infinitely if we get bad parent data.
    
    Fixes #7

 pyatspi/utils.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/pyatspi/utils.py b/pyatspi/utils.py
index 3bf185c..289faf9 100644
--- a/pyatspi/utils.py
+++ b/pyatspi/utils.py
@@ -296,7 +296,8 @@ def findAncestor(acc, pred):
         if acc is None:
                 # guard against bad start condition
                 return None
-        while 1:
+        tries = 0
+        while tries < 100:
                 if acc.parent is None:
                         # stop if there is no parent and we haven't returned yet
                         return None
@@ -306,6 +307,8 @@ def findAncestor(acc, pred):
                         pass
                 # move to the parent
                 acc = acc.parent
+                tries = tries + 1
+        return None
 
 def getPath(acc):
         """


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]