Skip to content

Commit 9c49d08

Browse files
committed
Rust: Adapt to changes in FlowSummaryImpl
1 parent 33133d8 commit 9c49d08

File tree

13 files changed

+184
-220
lines changed

13 files changed

+184
-220
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

rust/ql/test/library-tests/dataflow/local/inline-flow.expected

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ models
55
| 4 | Summary: <_ as core::ops::index::Index>::index; Argument[self].Reference.Element; ReturnValue.Reference; value |
66
| 5 | Summary: <alloc::boxed::Box as core::ops::deref::Deref>::deref; Argument[self].Reference.Field[alloc::boxed::Box(0)]; ReturnValue.Reference; value |
77
| 6 | Summary: <alloc::boxed::Box>::new; Argument[0]; ReturnValue.Field[alloc::boxed::Box(0)]; value |
8-
| 7 | Summary: <core::i64 as core::convert::From>::from; Argument[0]; ReturnValue; taint |
9-
| 8 | Summary: <core::option::Option>::unwrap; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
10-
| 9 | Summary: <core::option::Option>::unwrap_or; Argument[0]; ReturnValue; value |
11-
| 10 | Summary: <core::option::Option>::unwrap_or; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
12-
| 11 | Summary: <core::option::Option>::unwrap_or_else; Argument[0].ReturnValue; ReturnValue; value |
13-
| 12 | Summary: <core::option::Option>::unwrap_or_else; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
14-
| 13 | Summary: <core::result::Result>::err; Argument[self].Field[core::result::Result::Err(0)]; ReturnValue.Field[core::option::Option::Some(0)]; value |
15-
| 14 | Summary: <core::result::Result>::expect; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
16-
| 15 | Summary: <core::result::Result>::expect_err; Argument[self].Field[core::result::Result::Err(0)]; ReturnValue; value |
17-
| 16 | Summary: <core::result::Result>::ok; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue.Field[core::option::Option::Some(0)]; value |
18-
| 17 | Summary: <core::result::Result>::unwrap; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
19-
| 18 | Summary: <core::str>::parse; Argument[self]; ReturnValue.Field[core::result::Result::Ok(0)]; taint |
8+
| 7 | Summary: <core::option::Option>::unwrap; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
9+
| 8 | Summary: <core::option::Option>::unwrap_or; Argument[0]; ReturnValue; value |
10+
| 9 | Summary: <core::option::Option>::unwrap_or; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
11+
| 10 | Summary: <core::option::Option>::unwrap_or_else; Argument[0].ReturnValue; ReturnValue; value |
12+
| 11 | Summary: <core::option::Option>::unwrap_or_else; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
13+
| 12 | Summary: <core::result::Result>::err; Argument[self].Field[core::result::Result::Err(0)]; ReturnValue.Field[core::option::Option::Some(0)]; value |
14+
| 13 | Summary: <core::result::Result>::expect; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
15+
| 14 | Summary: <core::result::Result>::expect_err; Argument[self].Field[core::result::Result::Err(0)]; ReturnValue; value |
16+
| 15 | Summary: <core::result::Result>::ok; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue.Field[core::option::Option::Some(0)]; value |
17+
| 16 | Summary: <core::result::Result>::unwrap; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
18+
| 17 | Summary: <core::str>::parse; Argument[self]; ReturnValue.Field[core::result::Result::Ok(0)]; taint |
2019
edges
2120
| main.rs:23:9:23:9 | s | main.rs:24:10:24:10 | s | provenance | |
2221
| main.rs:23:9:23:9 | s | main.rs:26:12:26:12 | x | provenance | |
@@ -128,17 +127,17 @@ edges
128127
| main.rs:278:9:278:10 | s1 [Some] | main.rs:279:10:279:11 | s1 [Some] | provenance | |
129128
| main.rs:278:14:278:29 | Some(...) [Some] | main.rs:278:9:278:10 | s1 [Some] | provenance | |
130129
| main.rs:278:19:278:28 | source(...) | main.rs:278:14:278:29 | Some(...) [Some] | provenance | |
131-
| main.rs:279:10:279:11 | s1 [Some] | main.rs:279:10:279:20 | s1.unwrap() | provenance | MaD:8 |
130+
| main.rs:279:10:279:11 | s1 [Some] | main.rs:279:10:279:20 | s1.unwrap() | provenance | MaD:7 |
132131
| main.rs:283:9:283:10 | s1 [Some] | main.rs:284:10:284:11 | s1 [Some] | provenance | |
133132
| main.rs:283:14:283:29 | Some(...) [Some] | main.rs:283:9:283:10 | s1 [Some] | provenance | |
134133
| main.rs:283:19:283:28 | source(...) | main.rs:283:14:283:29 | Some(...) [Some] | provenance | |
135-
| main.rs:284:10:284:11 | s1 [Some] | main.rs:284:10:284:24 | s1.unwrap_or(...) | provenance | MaD:10 |
136-
| main.rs:287:23:287:32 | source(...) | main.rs:287:10:287:33 | s2.unwrap_or(...) | provenance | MaD:9 |
134+
| main.rs:284:10:284:11 | s1 [Some] | main.rs:284:10:284:24 | s1.unwrap_or(...) | provenance | MaD:9 |
135+
| main.rs:287:23:287:32 | source(...) | main.rs:287:10:287:33 | s2.unwrap_or(...) | provenance | MaD:8 |
137136
| main.rs:291:9:291:10 | s1 [Some] | main.rs:292:10:292:11 | s1 [Some] | provenance | |
138137
| main.rs:291:14:291:29 | Some(...) [Some] | main.rs:291:9:291:10 | s1 [Some] | provenance | |
139138
| main.rs:291:19:291:28 | source(...) | main.rs:291:14:291:29 | Some(...) [Some] | provenance | |
140-
| main.rs:292:10:292:11 | s1 [Some] | main.rs:292:10:292:32 | s1.unwrap_or_else(...) | provenance | MaD:12 |
141-
| main.rs:295:31:295:40 | source(...) | main.rs:295:10:295:41 | s2.unwrap_or_else(...) | provenance | MaD:11 |
139+
| main.rs:292:10:292:11 | s1 [Some] | main.rs:292:10:292:32 | s1.unwrap_or_else(...) | provenance | MaD:11 |
140+
| main.rs:295:31:295:40 | source(...) | main.rs:295:10:295:41 | s2.unwrap_or_else(...) | provenance | MaD:10 |
142141
| main.rs:299:9:299:10 | s1 [Some] | main.rs:301:14:301:15 | s1 [Some] | provenance | |
143142
| main.rs:299:14:299:29 | Some(...) [Some] | main.rs:299:9:299:10 | s1 [Some] | provenance | |
144143
| main.rs:299:19:299:28 | source(...) | main.rs:299:14:299:29 | Some(...) [Some] | provenance | |
@@ -149,16 +148,16 @@ edges
149148
| main.rs:308:32:308:45 | Ok(...) [Ok] | main.rs:308:9:308:10 | r1 [Ok] | provenance | |
150149
| main.rs:308:35:308:44 | source(...) | main.rs:308:32:308:45 | Ok(...) [Ok] | provenance | |
151150
| main.rs:309:9:309:11 | o1a [Some] | main.rs:311:10:311:12 | o1a [Some] | provenance | |
152-
| main.rs:309:28:309:29 | r1 [Ok] | main.rs:309:28:309:34 | r1.ok() [Some] | provenance | MaD:16 |
151+
| main.rs:309:28:309:29 | r1 [Ok] | main.rs:309:28:309:34 | r1.ok() [Some] | provenance | MaD:15 |
153152
| main.rs:309:28:309:34 | r1.ok() [Some] | main.rs:309:9:309:11 | o1a [Some] | provenance | |
154-
| main.rs:311:10:311:12 | o1a [Some] | main.rs:311:10:311:21 | o1a.unwrap() | provenance | MaD:8 |
153+
| main.rs:311:10:311:12 | o1a [Some] | main.rs:311:10:311:21 | o1a.unwrap() | provenance | MaD:7 |
155154
| main.rs:314:9:314:10 | r2 [Err] | main.rs:316:28:316:29 | r2 [Err] | provenance | |
156155
| main.rs:314:32:314:46 | Err(...) [Err] | main.rs:314:9:314:10 | r2 [Err] | provenance | |
157156
| main.rs:314:36:314:45 | source(...) | main.rs:314:32:314:46 | Err(...) [Err] | provenance | |
158157
| main.rs:316:9:316:11 | o2b [Some] | main.rs:318:10:318:12 | o2b [Some] | provenance | |
159-
| main.rs:316:28:316:29 | r2 [Err] | main.rs:316:28:316:35 | r2.err() [Some] | provenance | MaD:13 |
158+
| main.rs:316:28:316:29 | r2 [Err] | main.rs:316:28:316:35 | r2.err() [Some] | provenance | MaD:12 |
160159
| main.rs:316:28:316:35 | r2.err() [Some] | main.rs:316:9:316:11 | o2b [Some] | provenance | |
161-
| main.rs:318:10:318:12 | o2b [Some] | main.rs:318:10:318:21 | o2b.unwrap() | provenance | MaD:8 |
160+
| main.rs:318:10:318:12 | o2b [Some] | main.rs:318:10:318:21 | o2b.unwrap() | provenance | MaD:7 |
162161
| main.rs:322:9:322:10 | s1 [Ok] | main.rs:325:14:325:15 | s1 [Ok] | provenance | |
163162
| main.rs:322:32:322:45 | Ok(...) [Ok] | main.rs:322:9:322:10 | s1 [Ok] | provenance | |
164163
| main.rs:322:35:322:44 | source(...) | main.rs:322:32:322:45 | Ok(...) [Ok] | provenance | |
@@ -168,11 +167,11 @@ edges
168167
| main.rs:335:9:335:10 | s1 [Ok] | main.rs:336:10:336:11 | s1 [Ok] | provenance | |
169168
| main.rs:335:32:335:45 | Ok(...) [Ok] | main.rs:335:9:335:10 | s1 [Ok] | provenance | |
170169
| main.rs:335:35:335:44 | source(...) | main.rs:335:32:335:45 | Ok(...) [Ok] | provenance | |
171-
| main.rs:336:10:336:11 | s1 [Ok] | main.rs:336:10:336:22 | s1.expect(...) | provenance | MaD:14 |
170+
| main.rs:336:10:336:11 | s1 [Ok] | main.rs:336:10:336:22 | s1.expect(...) | provenance | MaD:13 |
172171
| main.rs:339:9:339:10 | s2 [Err] | main.rs:341:10:341:11 | s2 [Err] | provenance | |
173172
| main.rs:339:32:339:46 | Err(...) [Err] | main.rs:339:9:339:10 | s2 [Err] | provenance | |
174173
| main.rs:339:36:339:45 | source(...) | main.rs:339:32:339:46 | Err(...) [Err] | provenance | |
175-
| main.rs:341:10:341:11 | s2 [Err] | main.rs:341:10:341:26 | s2.expect_err(...) | provenance | MaD:15 |
174+
| main.rs:341:10:341:11 | s2 [Err] | main.rs:341:10:341:26 | s2.expect_err(...) | provenance | MaD:14 |
176175
| main.rs:350:9:350:10 | s1 [A] | main.rs:352:11:352:12 | s1 [A] | provenance | |
177176
| main.rs:350:14:350:39 | ...::A(...) [A] | main.rs:350:9:350:10 | s1 [A] | provenance | |
178177
| main.rs:350:29:350:38 | source(...) | main.rs:350:14:350:39 | ...::A(...) [A] | provenance | |
@@ -262,12 +261,12 @@ edges
262261
| main.rs:506:13:506:13 | a | main.rs:506:13:506:25 | a.to_string() | provenance | MaD:2 |
263262
| main.rs:506:13:506:25 | a.to_string() | main.rs:506:9:506:9 | b | provenance | |
264263
| main.rs:507:9:507:9 | c | main.rs:512:10:512:10 | c | provenance | |
265-
| main.rs:507:13:507:13 | b | main.rs:507:13:507:28 | b.parse() [Ok] | provenance | MaD:18 |
266-
| main.rs:507:13:507:28 | b.parse() [Ok] | main.rs:507:13:507:37 | ... .unwrap() | provenance | MaD:17 |
264+
| main.rs:507:13:507:13 | b | main.rs:507:13:507:28 | b.parse() [Ok] | provenance | MaD:17 |
265+
| main.rs:507:13:507:28 | b.parse() [Ok] | main.rs:507:13:507:37 | ... .unwrap() | provenance | MaD:16 |
267266
| main.rs:507:13:507:37 | ... .unwrap() | main.rs:507:9:507:9 | c | provenance | |
268267
| main.rs:508:9:508:9 | d | main.rs:513:10:513:10 | d | provenance | |
269-
| main.rs:508:18:508:18 | b | main.rs:508:18:508:26 | b.parse() [Ok] | provenance | MaD:18 |
270-
| main.rs:508:18:508:26 | b.parse() [Ok] | main.rs:508:18:508:35 | ... .unwrap() | provenance | MaD:17 |
268+
| main.rs:508:18:508:18 | b | main.rs:508:18:508:26 | b.parse() [Ok] | provenance | MaD:17 |
269+
| main.rs:508:18:508:26 | b.parse() [Ok] | main.rs:508:18:508:35 | ... .unwrap() | provenance | MaD:16 |
271270
| main.rs:508:18:508:35 | ... .unwrap() | main.rs:508:9:508:9 | d | provenance | |
272271
| main.rs:517:9:517:10 | vs [element] | main.rs:519:10:519:11 | vs [element] | provenance | |
273272
| main.rs:517:9:517:10 | vs [element] | main.rs:523:14:523:15 | vs [element] | provenance | |
@@ -298,7 +297,6 @@ edges
298297
| main.rs:572:9:572:9 | b | main.rs:576:20:576:20 | b | provenance | |
299298
| main.rs:572:18:572:27 | source(...) | main.rs:572:9:572:9 | b | provenance | |
300299
| main.rs:576:20:576:20 | b | main.rs:576:10:576:21 | ...::from(...) | provenance | MaD:3 |
301-
| main.rs:576:20:576:20 | b | main.rs:576:10:576:21 | ...::from(...) | provenance | MaD:7 |
302300
nodes
303301
| main.rs:19:10:19:18 | source(...) | semmle.label | source(...) |
304302
| main.rs:23:9:23:9 | s | semmle.label | s |

0 commit comments

Comments
 (0)