Skip to content

Commit 7724ab3

Browse files
committed
Rust: Adapt to changes in FlowSummaryImpl
1 parent 01ade0e commit 7724ab3

File tree

4 files changed

+37
-59
lines changed

4 files changed

+37
-59
lines changed

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

Lines changed: 7 additions & 3 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 = "QL"
2327
}
2428

2529
/**
@@ -31,6 +35,6 @@ module SummarizedCallable {
3135
}
3236
}
3337

34-
final class SummarizedCallable = SummarizedCallable::Range;
38+
final class SummarizedCallable = Impl::Public::RelevantSummarizedCallable;
3539

3640
final class Provenance = Impl::Public::Provenance;

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 callableFromSource(SummarizedCallableBase c) { 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: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -111,60 +111,35 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
111111
)
112112
}
113113

114-
private predicate summaryModel(
115-
Function f, string input, string output, string kind, Provenance provenance, boolean isInherited,
116-
QlBuiltins::ExtensionId madId
117-
) {
118-
exists(string path, Function f0 |
119-
summaryModel(path, input, output, kind, provenance, madId) and
120-
f0.getCanonicalPath() = path
121-
|
122-
f = f0 and
123-
isInherited = false
124-
or
125-
f.implements(f0) and
126-
isInherited = true
127-
)
128-
}
129-
130-
private predicate summaryModelRelevant(
131-
Function f, string input, string output, string kind, Provenance provenance, boolean isInherited,
132-
QlBuiltins::ExtensionId madId
133-
) {
134-
summaryModel(f, input, output, kind, provenance, isInherited, madId) and
135-
// Only apply generated or inherited models to functions in library code and
136-
// when no strictly better model exists
137-
if provenance.isGenerated() or isInherited = true
138-
then
139-
not f.fromSource() and
140-
not exists(Provenance other | summaryModel(f, _, _, _, other, false, _) |
141-
provenance.isGenerated() and other.isManual()
114+
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
115+
string input_;
116+
string output_;
117+
string kind;
118+
Provenance p_;
119+
boolean isExact_;
120+
QlBuiltins::ExtensionId madId;
121+
122+
SummarizedCallableFromModel() {
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
142128
or
143-
provenance = other and isInherited = true
129+
this.implements(f) and
130+
isExact_ = false
144131
)
145-
else any()
146-
}
147-
148-
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
149-
SummarizedCallableFromModel() { summaryModelRelevant(this, _, _, _, _, _, _) }
150-
151-
override predicate hasProvenance(Provenance provenance) {
152-
summaryModelRelevant(this, _, _, _, provenance, _, _)
153132
}
154133

155134
override predicate propagatesFlow(
156-
string input, string output, boolean preservesValue, string model
135+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
157136
) {
158-
exists(string kind, QlBuiltins::ExtensionId madId |
159-
summaryModelRelevant(this, input, output, kind, _, _, madId) and
160-
model = "MaD:" + madId.toString()
161-
|
162-
kind = "value" and
163-
preservesValue = true
164-
or
165-
kind = "taint" and
166-
preservesValue = false
167-
)
137+
input = input_ and
138+
output = output_ and
139+
(if kind = "value" then preservesValue = true else preservesValue = false) and
140+
p = p_ and
141+
isExact = isExact_ and
142+
model = "MaD:" + madId.toString()
168143
}
169144
}
170145

@@ -211,7 +186,7 @@ private module Debug {
211186
private predicate relevantManualModel(SummarizedCallableImpl sc, string can) {
212187
exists(Provenance manual |
213188
can = sc.getCanonicalPath() and
214-
summaryModelRelevant(sc, _, _, _, manual, false, _) and
189+
sc.(SummarizedCallableFromModel).propagatesFlow(_, _, _, manual, true, _) and
215190
manual.isManual()
216191
)
217192
}
@@ -221,7 +196,7 @@ private module Debug {
221196
) {
222197
exists(RustDataFlow::ParameterPosition pos, TypeMention tm |
223198
relevantManualModel(sc, can) and
224-
sc.propagatesFlow(input, _, _, _) and
199+
sc.propagatesFlow(input, _, _, _, _, _) and
225200
input.head() = SummaryComponent::argument(pos) and
226201
p = pos.getParameterIn(sc.getParamList()) and
227202
tm.resolveType() instanceof RefType and
@@ -238,7 +213,7 @@ private module Debug {
238213
) {
239214
exists(TypeMention tm |
240215
relevantManualModel(sc, can) and
241-
sc.propagatesFlow(_, output, _, _) and
216+
sc.propagatesFlow(_, output, _, _, _, _) and
242217
tm.resolveType() instanceof RefType and
243218
output.head() = SummaryComponent::return(_) and
244219
not output.tail().head() =

rust/ql/test/library-tests/dataflow/models/models.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ query predicate invalidSpecComponent(SummarizedCallable sc, string s, string c)
2222
private class SummarizedCallableIdentity extends SummarizedCallable::Range {
2323
SummarizedCallableIdentity() { this.getName().getText() = "identity" }
2424

25-
override predicate propagatesFlow(
26-
string input, string output, boolean preservesValue, string provenance
27-
) {
25+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
2826
input = "Argument[0]" and
2927
output = "ReturnValue" and
30-
preservesValue = true and
31-
provenance = "QL"
28+
preservesValue = true
3229
}
3330
}
3431

0 commit comments

Comments
 (0)