Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 061fd01

Browse files
committed
Python: further restrict LibraryLambdaMethod
On the small test project, this reduces the number of instances from 285 to 22.
1 parent 453ab9c commit 061fd01

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,30 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
9292
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
9393

9494
private module LibraryCallbackSummaries {
95+
private predicate libraryCall(CallCfgNode call) {
96+
not exists(NormalCall normalCall | call.getNode() = normalCall.getNode())
97+
}
98+
99+
private DataFlow::LocalSourceNode trackLambdaCreation(TypeTracker t) {
100+
t.start() and
101+
lambdaCreation(result, _, _)
102+
or
103+
exists(TypeTracker t2 | result = trackLambdaCreation(t2).track(t2, t)) and
104+
not result.(ParameterNode).getParameter().isSelf()
105+
}
106+
107+
private predicate libraryCallHasLambdaArg(CallCfgNode call, int i) {
108+
exists(CfgNode arg |
109+
arg = call.getArg(i) and
110+
arg.getALocalSource() = trackLambdaCreation(TypeTracker::end()) and
111+
libraryCall(call)
112+
)
113+
}
114+
95115
private class LibraryLambdaMethod extends SummarizedCallable {
96116
LibraryLambdaMethod() { this = "<library method accepting a callback>" }
97117

98-
final override CallCfgNode getACall() {
99-
not exists(NormalCall call | result.getNode() = call.getNode())
100-
}
118+
final override CallCfgNode getACall() { libraryCallHasLambdaArg(result, _) }
101119

102120
final override ArgumentNode getACallback() { none() }
103121

0 commit comments

Comments
 (0)