Skip to content

Commit cfb40fb

Browse files
authored
Merge pull request #23126 from hvitved/rust/call-back-summary-no-suppress
Rust: Prevent MaD suppression for heuristic call-back summary
2 parents 3db2468 + 7792dd0 commit cfb40fb

4 files changed

Lines changed: 355 additions & 304 deletions

File tree

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ predicate interpretPath(string path, Function f, Provenance orig, Provenance p,
194194
)
195195
}
196196

197+
private predicate summaryModel(
198+
Function f, string input, string output, string kind, Provenance p, boolean isExact,
199+
QlBuiltins::ExtensionId madId
200+
) {
201+
exists(string path, Provenance p_ |
202+
summaryModel(path, input, output, kind, p_, madId) and
203+
interpretPath(path, f, p_, p, isExact)
204+
)
205+
}
206+
197207
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
198208
string input_;
199209
string output_;
@@ -202,12 +212,7 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
202212
boolean isExact_;
203213
QlBuiltins::ExtensionId madId;
204214

205-
SummarizedCallableFromModel() {
206-
exists(string path, Provenance p |
207-
summaryModel(path, input_, output_, kind, p, madId) and
208-
interpretPath(path, this, p, p_, isExact_)
209-
)
210-
}
215+
SummarizedCallableFromModel() { summaryModel(this, input_, output_, kind, p_, isExact_, madId) }
211216

212217
override predicate propagatesFlow(
213218
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
@@ -237,6 +242,10 @@ predicate mayInvokeCallback(Function f, int n) {
237242
)
238243
}
239244

245+
private predicate hasGeneratedSummaryModel(Function f, boolean isExact) {
246+
summaryModel(f, _, _, _, any(Provenance g | g.isGenerated()), isExact, _)
247+
}
248+
240249
private class SummarizedCallableWithCallback extends SummarizedCallable::Range {
241250
private int pos;
242251

@@ -249,8 +258,15 @@ private class SummarizedCallableWithCallback extends SummarizedCallable::Range {
249258
output = "Argument[" + pos + "].Parameter[closure-self]" and
250259
preservesValue = true and
251260
p = "hq-generated" and
252-
isExact = true and
253-
model = "heuristic-callback"
261+
model = "heuristic-callback" and
262+
// If a generated model already exists for this function, inherit its exactness
263+
// to prevent that either model suppresses the other
264+
(
265+
hasGeneratedSummaryModel(this, isExact)
266+
or
267+
not hasGeneratedSummaryModel(this, _) and
268+
isExact = true
269+
)
254270
}
255271
}
256272

0 commit comments

Comments
 (0)