Skip to content
Prev Previous commit
Next Next commit
Rust: Define neutralElement in the shared data flow input.
  • Loading branch information
geoffw0 committed Feb 23, 2026
commit 6b7f3392877b58f6c3fa3c6cbe17a0feab287ac2
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ private import codeql.rust.dataflow.internal.DataFlowImpl
private import codeql.rust.internal.PathResolution
private import codeql.rust.dataflow.FlowSummary
private import codeql.rust.dataflow.Ssa
private import codeql.rust.dataflow.internal.ModelsAsData
private import Content

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

abstract class SinkBase extends SourceSinkBase { }

predicate neutralElement(
Input::SummarizedCallableBase c, string kind, string provenance, boolean isExact
) {
exists(string path |
neutralModel(path, kind, provenance, _) and
c.getCanonicalPath() = path and
isExact = true
)
}

private class CallExprFunction extends SourceBase, SinkBase {
private CallExpr call;

Expand Down
11 changes: 4 additions & 7 deletions rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,14 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
|
this = f and
isExact_ = true and
p_ = p and
// Do not apply generated models where there is a neutral model
not (
p_.isGenerated() and
neutralModel(path, "summary", _, _)
)
p_ = p
or
this.implements(f) and
isExact_ = false and
// making inherited models generated means that source code definitions and
// exact generated models take precedence
p_ = "hq-generated" and
// Do not apply inherited models where there is a neutral model
// Do not apply inherited models (which are considered generated) where there is a neutral model
not neutralModel(path, "summary", _, _)
Comment thread
geoffw0 marked this conversation as resolved.
Outdated
)
}
Expand Down Expand Up @@ -183,6 +178,7 @@ private class FlowSourceFromModel extends FlowSource::Range {
model = "MaD:" + madId.toString()
) and
// Only apply generated models when no neutral model exists
// (the shared code only applies neutral models to summaries at present)
not (
provenance.isGenerated() and
neutralModel(path, "source", _, _)
Expand All @@ -204,6 +200,7 @@ private class FlowSinkFromModel extends FlowSink::Range {
model = "MaD:" + madId.toString()
) and
// Only apply generated models when no neutral model exists
// (the shared code only applies neutral models to summaries at present)
not (
provenance.isGenerated() and
neutralModel(path, "sink", _, _)
Expand Down
Loading