Skip to content

Commit 52cbb67

Browse files
committed
Rust: Evaluate mayInvokeCallback in type inference stage
1 parent 1e6ef80 commit 52cbb67

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private import codeql.rust.dataflow.FlowBarrier
5858
private import codeql.rust.dataflow.FlowSummary
5959
private import codeql.rust.dataflow.FlowSource
6060
private import codeql.rust.dataflow.FlowSink
61+
private import codeql.rust.internal.CachedStages
6162
private import codeql.rust.internal.typeinference.FunctionType
6263
private import codeql.rust.internal.typeinference.TypeMention
6364
private import codeql.rust.frameworks.stdlib.Stdlib
@@ -215,7 +216,9 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
215216
* add a flow model that achieves the effect of simulating that the callback is
216217
* invoked, which is needed for flow through captured variables to work.
217218
*/
218-
private predicate mayInvokeCallback(Function f, int n) {
219+
cached
220+
predicate mayInvokeCallback(Function f, int n) {
221+
Stages::TypeInferenceStage::ref() and
219222
exists(TypeMention tm, Trait trait |
220223
tm = f.getParam(n).getTypeRepr() and
221224
trait = getALookupTrait(f, tm.getType()) and

rust/ql/lib/codeql/rust/internal/CachedStages.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ module Stages {
130130
module TypeInferenceStage {
131131
private import codeql.rust.internal.typeinference.Type
132132
private import codeql.rust.internal.typeinference.TypeInference
133+
private import codeql.rust.dataflow.internal.ModelsAsData
133134

134135
/**
135136
* Always holds.
@@ -150,6 +151,8 @@ module Stages {
150151
exists(Type t)
151152
or
152153
exists(inferType(_))
154+
or
155+
mayInvokeCallback(_, _)
153156
}
154157
}
155158

0 commit comments

Comments
 (0)