Skip to content

Commit b85ef1a

Browse files
committed
Rust: Adapt to changes in FlowSummaryImpl
1 parent 8b82020 commit b85ef1a

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

rust/ql/lib/codeql/rust/dataflow/FlowSummary.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ module SummarizedCallable {
1717
Range() { any() }
1818

1919
override predicate propagatesFlow(
20-
string input, string output, boolean preservesValue, string model
20+
string input, string output, boolean preservesValue, Provenance p, boolean isExact,
21+
string model
2122
) {
22-
this.propagatesFlow(input, output, preservesValue) and model = ""
23+
this.propagatesFlow(input, output, preservesValue) and
24+
p = "manual" and
25+
isExact = true and
26+
model = ""
2327
}
2428

2529
/**

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -443,25 +443,7 @@ module RustDataFlow implements InputSig<Location> {
443443
exists(Call c | c = call.asCall() |
444444
result.asCfgScope() = c.getARuntimeTarget()
445445
or
446-
exists(SummarizedCallable sc, Function staticTarget |
447-
staticTarget = getStaticTargetExt(c) and
448-
sc = result.asSummarizedCallable() and
449-
// Only use summarized callables with generated summaries in case
450-
// the static call target is not in the source code.
451-
// Note that if `applyGeneratedModel` holds it implies that there doesn't
452-
// exist a manual model.
453-
not (
454-
staticTarget.fromSource() and
455-
sc.applyGeneratedModel()
456-
)
457-
|
458-
sc = staticTarget
459-
or
460-
// only apply trait models to concrete implementations when they are not
461-
// defined in source code
462-
staticTarget.implements(sc) and
463-
not staticTarget.fromSource()
464-
)
446+
result.asSummarizedCallable() = getStaticTargetExt(c)
465447
)
466448
}
467449

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module Input implements InputSig<Location, RustDataFlow> {
3030

3131
class SummarizedCallableBase = Function;
3232

33+
predicate allowGeneratedSummary(SummarizedCallableBase c) { not c.fromSource() }
34+
3335
abstract private class SourceSinkBase extends AstNode {
3436
/** Gets the associated call. */
3537
abstract Call getCall();

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,33 +112,37 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
112112
}
113113

114114
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
115-
private string path;
115+
string input_;
116+
string output_;
117+
string kind;
118+
Provenance p_;
119+
boolean isExact_;
120+
QlBuiltins::ExtensionId madId;
116121

117122
SummarizedCallableFromModel() {
118-
summaryModel(path, _, _, _, _, _) and
119-
this.getCanonicalPath() = path
120-
}
121-
122-
override predicate hasProvenance(Provenance provenance) {
123-
summaryModel(path, _, _, _, provenance, _)
123+
exists(string path, Function f |
124+
summaryModel(path, input_, output_, kind, p_, madId) and
125+
f.getCanonicalPath() = path
126+
|
127+
this = f and isExact_ = true
128+
or
129+
// only apply trait models to concrete implementations when they are not
130+
// defined in source code
131+
this.implements(f) and
132+
isExact_ = false and
133+
not this.fromSource()
134+
)
124135
}
125136

126-
private predicate hasManualModel() { summaryModel(path, _, _, _, "manual", _) }
127-
128137
override predicate propagatesFlow(
129-
string input, string output, boolean preservesValue, string model
138+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
130139
) {
131-
exists(string kind, string provenance, QlBuiltins::ExtensionId madId |
132-
summaryModel(path, input, output, kind, provenance, madId) and
133-
model = "MaD:" + madId.toString() and
134-
(provenance = "manual" or not this.hasManualModel())
135-
|
136-
kind = "value" and
137-
preservesValue = true
138-
or
139-
kind = "taint" and
140-
preservesValue = false
141-
)
140+
input = input_ and
141+
output = output_ and
142+
(if kind = "value" then preservesValue = true else preservesValue = false) and
143+
p = p_ and
144+
isExact = isExact_ and
145+
model = "MaD:" + madId.toString()
142146
}
143147
}
144148

0 commit comments

Comments
 (0)