Skip to content

Commit 6b7f339

Browse files
committed
Rust: Define neutralElement in the shared data flow input.
1 parent a5aeadd commit 6b7f339

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private import codeql.rust.dataflow.internal.DataFlowImpl
99
private import codeql.rust.internal.PathResolution
1010
private import codeql.rust.dataflow.FlowSummary
1111
private import codeql.rust.dataflow.Ssa
12+
private import codeql.rust.dataflow.internal.ModelsAsData
1213
private import Content
1314

1415
predicate encodeContentTupleField(TupleFieldContent c, string arg) {
@@ -46,6 +47,16 @@ module Input implements InputSig<Location, RustDataFlow> {
4647

4748
abstract class SinkBase extends SourceSinkBase { }
4849

50+
predicate neutralElement(
51+
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
52+
) {
53+
exists(string path |
54+
neutralModel(path, kind, provenance, _) and
55+
c.getCanonicalPath() = path and
56+
isExact = true
57+
)
58+
}
59+
4960
private class CallExprFunction extends SourceBase, SinkBase {
5061
private CallExpr call;
5162

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,14 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
140140
|
141141
this = f and
142142
isExact_ = true and
143-
p_ = p and
144-
// Do not apply generated models where there is a neutral model
145-
not (
146-
p_.isGenerated() and
147-
neutralModel(path, "summary", _, _)
148-
)
143+
p_ = p
149144
or
150145
this.implements(f) and
151146
isExact_ = false and
152147
// making inherited models generated means that source code definitions and
153148
// exact generated models take precedence
154149
p_ = "hq-generated" and
155-
// Do not apply inherited models where there is a neutral model
150+
// Do not apply inherited models (which are considered generated) where there is a neutral model
156151
not neutralModel(path, "summary", _, _)
157152
)
158153
}
@@ -183,6 +178,7 @@ private class FlowSourceFromModel extends FlowSource::Range {
183178
model = "MaD:" + madId.toString()
184179
) and
185180
// Only apply generated models when no neutral model exists
181+
// (the shared code only applies neutral models to summaries at present)
186182
not (
187183
provenance.isGenerated() and
188184
neutralModel(path, "source", _, _)
@@ -204,6 +200,7 @@ private class FlowSinkFromModel extends FlowSink::Range {
204200
model = "MaD:" + madId.toString()
205201
) and
206202
// Only apply generated models when no neutral model exists
203+
// (the shared code only applies neutral models to summaries at present)
207204
not (
208205
provenance.isGenerated() and
209206
neutralModel(path, "sink", _, _)

0 commit comments

Comments
 (0)