Skip to content

Commit e3883da

Browse files
committed
unified: Add basic escape
Now that all data flow nodes are in Expr, we get more noise if we don't restrict this
1 parent d0d1363 commit e3883da

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/dataflow/CaptureSsa.qll‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ module CaptureSsaInput implements InputSig<Location, BasicBlock> {
9090
)
9191
}
9292

93+
private predicate isEscape(BuilderNode node) {
94+
node.isResultValue(any(Argument arg).getValue())
95+
or
96+
node.isImplicitArgument(_, _, _)
97+
or
98+
exists(U::Expr e |
99+
isReturnedExpr(_, e) and
100+
node.isResultValue(e)
101+
)
102+
or
103+
step(node, any(Step s | s.store(_)), _)
104+
}
105+
93106
class ClosureExpr extends Expr instanceof TCallableNode {
94107
// TODO: In order to support classes with captures, this needs to cover constructor calls to such classes as well.
95108
private Callable callable;
@@ -99,8 +112,8 @@ module CaptureSsaInput implements InputSig<Location, BasicBlock> {
99112
predicate hasBody(Callable body) { callable = body }
100113

101114
predicate hasAliasedAccess(Expr f) {
102-
// TODO: Restrict to places where the function is called or escapes into a call where it might get called.
103-
callableHasLocalAlias(callable, f) and not f.(LocalVariableRefNode).getRefKind().isWrite()
115+
callableHasLocalAlias(callable, f) and
116+
isEscape(f)
104117
}
105118
}
106119
}

0 commit comments

Comments
 (0)