Skip to content

Commit cea8d5f

Browse files
committed
wip
1 parent 4e1a5d4 commit cea8d5f

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ final private class ExprOutNode extends ExprNode, OutNode {
372372
class DerefOutNode extends OutNode, TDerefOutNode {
373373
DerefExpr de;
374374

375-
DerefOutNode() { this = TDerefOutNode(de) }
375+
DerefOutNode() { this = TDerefOutNode(de, false) }
376376

377377
DerefExpr getDerefExpr() { result = de }
378378

@@ -465,6 +465,18 @@ final class DerefBorrowPostUpdateNode extends PostUpdateNode, TDerefBorrowNode {
465465
override Location getLocation() { result = arg.getLocation() }
466466
}
467467

468+
class DerefOutPostUpdateNode extends PostUpdateNode, TDerefOutNode {
469+
DerefExpr de;
470+
471+
DerefOutPostUpdateNode() { this = TDerefOutNode(de, true) }
472+
473+
override DerefOutNode getPreUpdateNode() { result = TDerefOutNode(de, false) }
474+
475+
override CfgScope getCfgScope() { result = de.getEnclosingCfgScope() }
476+
477+
override Location getLocation() { result = de.getLocation() }
478+
}
479+
468480
final class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNode {
469481
private FlowSummaryNode pre;
470482

@@ -530,7 +542,7 @@ newtype TNode =
530542
TypeInference::implicitBorrow(n) and
531543
borrow = true
532544
} or
533-
TDerefOutNode(DerefExpr de) or
545+
TDerefOutNode(DerefExpr de, Boolean isPost) or
534546
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) or
535547
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) {
536548
forall(AstNode n | n = sn.getSinkElement() or n = sn.getSourceElement() |

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
models
2-
| 1 | Summary: futures_executor::local_pool::block_on; Argument[0]; ReturnValue; value |
2+
| 1 | Summary: <& as core::ops::deref::Deref>::deref; Argument[self].Reference; ReturnValue; value |
3+
| 2 | Summary: futures_executor::local_pool::block_on; Argument[0]; ReturnValue; value |
34
edges
45
| main.rs:12:28:14:1 | { ... } | main.rs:17:13:17:23 | get_data(...) | provenance | |
56
| main.rs:13:5:13:13 | source(...) | main.rs:12:28:14:1 | { ... } | provenance | |
@@ -118,7 +119,7 @@ edges
118119
| main.rs:236:9:236:22 | &... [&ref] | main.rs:235:38:237:5 | { ... } [&ref] | provenance | |
119120
| main.rs:236:10:236:22 | ... .value | main.rs:236:9:236:22 | &... [&ref] | provenance | |
120121
| main.rs:236:11:236:15 | * ... [MyInt] | main.rs:236:10:236:22 | ... .value | provenance | |
121-
| main.rs:236:12:236:15 | self [&ref, MyInt] | main.rs:236:11:236:15 | * ... [MyInt] | provenance | |
122+
| main.rs:236:12:236:15 | self [&ref, MyInt] | main.rs:236:11:236:15 | * ... [MyInt] | provenance | MaD:1 |
122123
| main.rs:242:9:242:9 | a [MyInt] | main.rs:244:13:244:13 | a [MyInt] | provenance | |
123124
| main.rs:242:13:242:38 | MyInt {...} [MyInt] | main.rs:242:9:242:9 | a [MyInt] | provenance | |
124125
| main.rs:242:28:242:36 | source(...) | main.rs:242:13:242:38 | MyInt {...} [MyInt] | provenance | |
@@ -148,17 +149,17 @@ edges
148149
| main.rs:270:28:270:37 | source(...) | main.rs:270:13:270:39 | MyInt {...} [MyInt] | provenance | |
149150
| main.rs:272:9:272:9 | c | main.rs:273:10:273:10 | c | provenance | |
150151
| main.rs:272:13:272:29 | * ... | main.rs:272:9:272:9 | c | provenance | |
151-
| main.rs:272:14:272:29 | ...::deref(...) [&ref] | main.rs:272:13:272:29 | * ... | provenance | |
152+
| main.rs:272:14:272:29 | ...::deref(...) [&ref] | main.rs:272:13:272:29 | * ... | provenance | MaD:1 |
152153
| main.rs:272:27:272:28 | &a [&ref, MyInt] | main.rs:235:14:235:18 | SelfParam [&ref, MyInt] | provenance | |
153-
| main.rs:272:27:272:28 | &a [&ref, MyInt] | main.rs:272:14:272:29 | ...::deref(...) [&ref] | provenance | |
154+
| main.rs:272:27:272:28 | &a [&ref, MyInt] | main.rs:272:14:272:29 | ...::deref(...) [&ref] | provenance | MaD:1 |
154155
| main.rs:272:28:272:28 | a [MyInt] | main.rs:272:27:272:28 | &a [&ref, MyInt] | provenance | |
155156
| main.rs:275:9:275:9 | a [MyInt] | main.rs:276:14:276:14 | a [MyInt] | provenance | |
156157
| main.rs:275:13:275:39 | MyInt {...} [MyInt] | main.rs:275:9:275:9 | a [MyInt] | provenance | |
157158
| main.rs:275:28:275:37 | source(...) | main.rs:275:13:275:39 | MyInt {...} [MyInt] | provenance | |
158-
| main.rs:276:9:276:9 | c [&ref] | main.rs:277:10:277:10 | c | provenance | |
159-
| main.rs:276:13:276:14 | * ... [&ref] | main.rs:276:9:276:9 | c [&ref] | provenance | |
159+
| main.rs:276:9:276:9 | c | main.rs:277:10:277:10 | c | provenance | |
160+
| main.rs:276:13:276:14 | * ... | main.rs:276:9:276:9 | c | provenance | |
160161
| main.rs:276:14:276:14 | a [MyInt] | main.rs:235:14:235:18 | SelfParam [&ref, MyInt] | provenance | |
161-
| main.rs:276:14:276:14 | a [MyInt] | main.rs:276:13:276:14 | * ... [&ref] | provenance | |
162+
| main.rs:276:14:276:14 | a [MyInt] | main.rs:276:13:276:14 | * ... | provenance | MaD:1 |
162163
| main.rs:289:18:289:21 | SelfParam [MyInt] | main.rs:289:48:291:5 | { ... } [MyInt] | provenance | |
163164
| main.rs:293:26:293:37 | ...: MyInt [MyInt] | main.rs:293:49:295:5 | { ... } [MyInt] | provenance | |
164165
| main.rs:299:9:299:9 | a [MyInt] | main.rs:301:50:301:50 | a [MyInt] | provenance | |
@@ -185,7 +186,7 @@ edges
185186
| main.rs:326:17:326:25 | source(...) | main.rs:326:13:326:13 | c | provenance | |
186187
| main.rs:334:9:334:9 | a | main.rs:335:10:335:10 | a | provenance | |
187188
| main.rs:334:13:334:55 | ...::block_on(...) | main.rs:334:9:334:9 | a | provenance | |
188-
| main.rs:334:41:334:54 | async_source(...) | main.rs:334:13:334:55 | ...::block_on(...) | provenance | MaD:1 |
189+
| main.rs:334:41:334:54 | async_source(...) | main.rs:334:13:334:55 | ...::block_on(...) | provenance | MaD:2 |
189190
nodes
190191
| main.rs:12:28:14:1 | { ... } | semmle.label | { ... } |
191192
| main.rs:13:5:13:13 | source(...) | semmle.label | source(...) |
@@ -355,8 +356,8 @@ nodes
355356
| main.rs:275:9:275:9 | a [MyInt] | semmle.label | a [MyInt] |
356357
| main.rs:275:13:275:39 | MyInt {...} [MyInt] | semmle.label | MyInt {...} [MyInt] |
357358
| main.rs:275:28:275:37 | source(...) | semmle.label | source(...) |
358-
| main.rs:276:9:276:9 | c [&ref] | semmle.label | c [&ref] |
359-
| main.rs:276:13:276:14 | * ... [&ref] | semmle.label | * ... [&ref] |
359+
| main.rs:276:9:276:9 | c | semmle.label | c |
360+
| main.rs:276:13:276:14 | * ... | semmle.label | * ... |
360361
| main.rs:276:14:276:14 | a [MyInt] | semmle.label | a [MyInt] |
361362
| main.rs:277:10:277:10 | c | semmle.label | c |
362363
| main.rs:289:18:289:21 | SelfParam [MyInt] | semmle.label | SelfParam [MyInt] |
@@ -407,7 +408,7 @@ subpaths
407408
| main.rs:254:13:254:13 | a [MyInt] | main.rs:220:12:220:15 | SelfParam [MyInt] | main.rs:220:42:223:5 | { ... } [MyInt] | main.rs:254:13:254:20 | a.add(...) [MyInt] |
408409
| main.rs:261:35:261:35 | b [MyInt] | main.rs:227:30:227:39 | ...: MyInt [MyInt] | main.rs:227:19:227:27 | SelfParam [Return] [&ref, MyInt] | main.rs:261:27:261:32 | [post] &mut a [&ref, MyInt] |
409410
| main.rs:272:27:272:28 | &a [&ref, MyInt] | main.rs:235:14:235:18 | SelfParam [&ref, MyInt] | main.rs:235:38:237:5 | { ... } [&ref] | main.rs:272:14:272:29 | ...::deref(...) [&ref] |
410-
| main.rs:276:14:276:14 | a [MyInt] | main.rs:235:14:235:18 | SelfParam [&ref, MyInt] | main.rs:235:38:237:5 | { ... } [&ref] | main.rs:276:13:276:14 | * ... [&ref] |
411+
| main.rs:276:14:276:14 | a [MyInt] | main.rs:235:14:235:18 | SelfParam [&ref, MyInt] | main.rs:235:38:237:5 | { ... } [&ref] | main.rs:276:13:276:14 | * ... |
411412
| main.rs:301:50:301:50 | a [MyInt] | main.rs:289:18:289:21 | SelfParam [MyInt] | main.rs:289:48:291:5 | { ... } [MyInt] | main.rs:301:30:301:54 | ...::take_self(...) [MyInt] |
412413
| main.rs:306:55:306:55 | b [MyInt] | main.rs:293:26:293:37 | ...: MyInt [MyInt] | main.rs:293:49:295:5 | { ... } [MyInt] | main.rs:306:30:306:56 | ...::take_second(...) [MyInt] |
413414
testFailures

rust/ql/test/library-tests/dataflow/global/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn test_operator_overloading() {
274274

275275
let a = MyInt { value: source(28) };
276276
let c = *a;
277-
sink(c); // $ hasTaintFlow=28 MISSING: hasValueFlow=28
277+
sink(c); // $ hasValueFlow=28
278278
}
279279

280280
trait MyTrait2 {

rust/ql/test/library-tests/dataflow/global/viableCallable.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
| main.rs:212:13:212:34 | ...::new(...) | main.rs:205:5:208:5 | fn new |
6060
| main.rs:212:24:212:33 | source(...) | main.rs:1:1:3:1 | fn source |
6161
| main.rs:214:5:214:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
62+
| main.rs:236:11:236:15 | * ... | {EXTERNAL LOCATION} | fn deref |
63+
| main.rs:236:11:236:15 | * ... | {EXTERNAL LOCATION} | fn deref |
6264
| main.rs:242:28:242:36 | source(...) | main.rs:1:1:3:1 | fn source |
6365
| main.rs:244:13:244:17 | ... + ... | main.rs:220:5:223:5 | fn add |
6466
| main.rs:245:5:245:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
@@ -75,6 +77,8 @@
7577
| main.rs:266:5:266:10 | ... *= ... | main.rs:227:5:229:5 | fn mul_assign |
7678
| main.rs:267:5:267:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
7779
| main.rs:270:28:270:37 | source(...) | main.rs:1:1:3:1 | fn source |
80+
| main.rs:272:13:272:29 | * ... | {EXTERNAL LOCATION} | fn deref |
81+
| main.rs:272:13:272:29 | * ... | {EXTERNAL LOCATION} | fn deref |
7882
| main.rs:272:14:272:29 | ...::deref(...) | main.rs:235:5:237:5 | fn deref |
7983
| main.rs:273:5:273:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
8084
| main.rs:275:28:275:37 | source(...) | main.rs:1:1:3:1 | fn source |

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
models
2+
| 1 | Summary: <& as core::ops::deref::Deref>::deref; Argument[self].Reference; ReturnValue; value |
23
edges
34
| main.rs:17:13:17:13 | a | main.rs:18:18:18:18 | a | provenance | |
45
| main.rs:17:17:17:26 | source(...) | main.rs:17:13:17:13 | a | provenance | |
@@ -7,7 +8,7 @@ edges
78
| main.rs:18:18:18:18 | a | main.rs:18:17:18:18 | &a [&ref] | provenance | |
89
| main.rs:19:13:19:13 | c | main.rs:20:14:20:14 | c | provenance | |
910
| main.rs:19:17:19:18 | * ... | main.rs:19:13:19:13 | c | provenance | |
10-
| main.rs:19:18:19:18 | b [&ref] | main.rs:19:17:19:18 | * ... | provenance | |
11+
| main.rs:19:18:19:18 | b [&ref] | main.rs:19:17:19:18 | * ... | provenance | MaD:1 |
1112
| main.rs:23:29:23:30 | &... [&ref] | main.rs:23:30:23:30 | n | provenance | |
1213
| main.rs:23:29:23:36 | ...: ... [&ref] | main.rs:23:29:23:30 | &... [&ref] | provenance | |
1314
| main.rs:23:30:23:30 | n | main.rs:24:14:24:14 | n | provenance | |
@@ -28,25 +29,25 @@ edges
2829
| main.rs:51:17:51:26 | source(...) | main.rs:51:13:51:13 | a | provenance | |
2930
| main.rs:52:13:52:17 | ref p | main.rs:52:17:52:17 | p [&ref] | provenance | |
3031
| main.rs:52:17:52:17 | p [&ref] | main.rs:53:15:53:15 | p [&ref] | provenance | |
31-
| main.rs:53:15:53:15 | p [&ref] | main.rs:53:14:53:15 | * ... | provenance | |
32+
| main.rs:53:15:53:15 | p [&ref] | main.rs:53:14:53:15 | * ... | provenance | MaD:1 |
3233
| main.rs:57:13:57:13 | a [Some] | main.rs:58:15:58:15 | a [Some] | provenance | |
3334
| main.rs:57:17:57:32 | Some(...) [Some] | main.rs:57:13:57:13 | a [Some] | provenance | |
3435
| main.rs:57:22:57:31 | source(...) | main.rs:57:17:57:32 | Some(...) [Some] | provenance | |
3536
| main.rs:58:15:58:15 | a [Some] | main.rs:59:13:59:23 | Some(...) [Some] | provenance | |
3637
| main.rs:59:13:59:23 | Some(...) [Some] | main.rs:59:18:59:22 | ref p | provenance | |
3738
| main.rs:59:18:59:22 | ref p | main.rs:59:22:59:22 | p [&ref] | provenance | |
3839
| main.rs:59:22:59:22 | p [&ref] | main.rs:59:34:59:34 | p [&ref] | provenance | |
39-
| main.rs:59:34:59:34 | p [&ref] | main.rs:59:33:59:34 | * ... | provenance | |
40+
| main.rs:59:34:59:34 | p [&ref] | main.rs:59:33:59:34 | * ... | provenance | MaD:1 |
4041
| main.rs:73:10:73:10 | [post] b [&ref] | main.rs:74:15:74:15 | b [&ref] | provenance | |
4142
| main.rs:73:14:73:23 | source(...) | main.rs:73:10:73:10 | [post] b [&ref] | provenance | |
42-
| main.rs:74:15:74:15 | b [&ref] | main.rs:74:14:74:15 | * ... | provenance | |
43+
| main.rs:74:15:74:15 | b [&ref] | main.rs:74:14:74:15 | * ... | provenance | MaD:1 |
4344
| main.rs:105:10:105:10 | [post] c [&ref] | main.rs:106:15:106:15 | c [&ref] | provenance | |
4445
| main.rs:105:14:105:23 | source(...) | main.rs:105:10:105:10 | [post] c [&ref] | provenance | |
45-
| main.rs:106:15:106:15 | c [&ref] | main.rs:106:14:106:15 | * ... | provenance | |
46+
| main.rs:106:15:106:15 | c [&ref] | main.rs:106:14:106:15 | * ... | provenance | MaD:1 |
4647
| main.rs:112:13:112:21 | ref mut a | main.rs:112:21:112:21 | a [&ref] | provenance | |
4748
| main.rs:112:21:112:21 | a [&ref] | main.rs:113:15:113:15 | a [&ref] | provenance | |
4849
| main.rs:112:25:112:34 | source(...) | main.rs:112:13:112:21 | ref mut a | provenance | |
49-
| main.rs:113:15:113:15 | a [&ref] | main.rs:113:14:113:15 | * ... | provenance | |
50+
| main.rs:113:15:113:15 | a [&ref] | main.rs:113:14:113:15 | * ... | provenance | MaD:1 |
5051
| main.rs:149:14:149:24 | ...: MyNumber [MyNumber] | main.rs:150:11:150:11 | m [MyNumber] | provenance | |
5152
| main.rs:150:11:150:11 | m [MyNumber] | main.rs:151:9:151:34 | ...::MyNumber(...) [MyNumber] | provenance | |
5253
| main.rs:151:9:151:34 | ...::MyNumber(...) [MyNumber] | main.rs:151:28:151:33 | number | provenance | |
@@ -88,7 +89,7 @@ edges
8889
| main.rs:210:17:210:17 | [post] p [&ref] | main.rs:211:15:211:15 | p [&ref] | provenance | |
8990
| main.rs:210:20:210:29 | source(...) | main.rs:200:29:200:38 | ...: i64 | provenance | |
9091
| main.rs:210:20:210:29 | source(...) | main.rs:210:17:210:17 | [post] p [&ref] | provenance | |
91-
| main.rs:211:15:211:15 | p [&ref] | main.rs:211:14:211:15 | * ... | provenance | |
92+
| main.rs:211:15:211:15 | p [&ref] | main.rs:211:14:211:15 | * ... | provenance | MaD:1 |
9293
| main.rs:218:17:218:22 | [post] &mut n [&ref] | main.rs:218:22:218:22 | [post] n | provenance | |
9394
| main.rs:218:22:218:22 | [post] n | main.rs:219:14:219:14 | n | provenance | |
9495
| main.rs:218:25:218:34 | source(...) | main.rs:200:29:200:38 | ...: i64 | provenance | |

0 commit comments

Comments
 (0)