Private
Public Access
fix(scripts): visit_Try walker now visits ALL except handlers
The audit script's visit_Try had a bug where the \or child in handler.body\ loop was OUTSIDE the \or handler in node.handlers\ loop. So \handler\ was bound to the LAST handler, and only the last handler's body was walked. Raises in non-last except handlers were missed (e.g., src/rag_engine.py:31 was not in the audit findings). The fix moves the inner loop inside the outer loop so each handler's body is walked. Both the FIRST and LAST handler raises are now detected. Adds tests/test_audit_exception_handling_bug_fixes.py with 2 tests for the walker behavior (first-handler raise, middle-handler raise in a 3-handler try).
This commit is contained in:
@@ -771,8 +771,8 @@ class ExceptionVisitor(ast.NodeVisitor):
|
||||
for handler in node.handlers:
|
||||
category, hint = self._classify_except(handler, node)
|
||||
self._add_finding("EXCEPT", handler.lineno, self._snippet(handler), category, hint)
|
||||
for child in handler.body if node.handlers else []:
|
||||
self.visit(child)
|
||||
for child in handler.body:
|
||||
self.visit(child)
|
||||
for child in node.orelse:
|
||||
self.visit(child)
|
||||
for child in node.finalbody:
|
||||
|
||||
Reference in New Issue
Block a user