sonar-cryptography icon indicating copy to clipboard operation
sonar-cryptography copied to clipboard

fix: add recursion guard to traceSymbol to prevent StackOverflow on mutual assignment cycles

Open Ayush-Patel-56 opened this issue 6 months ago • 0 comments

Summary

Fixes #400

Note: depends on #390. Once that merges this PR will show only the 4 files relevant to the recursion guard.

  • Adds a visited: Set<Symbol> overload to traceSymbol in both PythonDetectionEngine and JavaDetectionEngine
  • The public overload delegates to the private one with new HashSet<>(), so all call sites are unchanged
  • On the first revisit of any symbol the guard returns the current symbol immediately, terminating the cycle

Test plan

  • [ ] Issue400RecursionGuardTest (Python) — verifies a mutual assignment cycle (alg = intermediary; intermediary = alg) completes within 10 s without StackOverflowError and still detects AES
  • [ ] Issue8IntermediaryVariableTest (Python) — regression: single-hop indirection still resolves correctly
  • [ ] Issue8IntermediaryVariableTest (Java) — regression: intermediary variable chain still resolves correctly
  • [ ] Issue8MethodReceiverTest (Java) — regression: method-receiver intermediary still resolves correctly

Ayush-Patel-56 avatar May 06 '26 11:05 Ayush-Patel-56