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

Add recursion guard to traceSymbol in Java and Python detection engines

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

Summary

traceSymbol in both JavaDetectionEngine and PythonDetectionEngine follows variable initializer chains recursively but has no cycle detection. A self-referential or mutually recursive assignment (e.g. x = x) would cause a StackOverflowError at analysis time.

Steps to reproduce

// hypothetical pathological input
SomeType x = x; // self-referential

Expected behavior

Detection gracefully stops at the cycle and returns the last seen symbol.

Suggested fix

Track visited symbols in a Set and return early if a symbol has already been seen during the current trace.

private Symbol traceSymbol(Symbol symbol, Set<Symbol> visited) {
    if (!visited.add(symbol)) return symbol;
    // ... existing logic
}

Context

Identified during review of PR #390. The fix for intermediary variable detection intentionally left this out to keep the scope minimal. Tracked here as a follow-up.

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

Blocked by #390.

This issue asks for a recursion guard in traceSymbol. That method does not exist on main — it is added by #390, which is still open. So there is nothing to guard yet.

Keeping this open as a follow-up. It becomes actionable once #390 is merged. Whoever reviews #390 should check the cycle case there as well, so we may not need a second round.

n1ckl0sk0rtge avatar Aug 21 '26 08:08 n1ckl0sk0rtge