Skip to content

Commit 063aefe

Browse files
committed
data flow wip
1 parent 4e8b592 commit 063aefe

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ module RustDataFlow implements InputSig<Location> {
582582
.isVariantField([any(OptionEnum o).getSome(), any(ResultEnum r).getOk()], 0)
583583
)
584584
or
585+
// todo: rely on flow summary instead
585586
exists(PrefixExprCfgNode deref |
586587
c instanceof ReferenceContent and
587588
deref.getOperatorName() = "*" and

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ newtype TNode =
467467
any(TryExprCfgNode try).getExpr(), //
468468
any(PrefixExprCfgNode pe | pe.getOperatorName() = "*").getExpr(), //
469469
any(AwaitExprCfgNode a).getExpr(), //
470-
any(MethodCallExprCfgNode mc).getReceiver(), //
470+
any(CallCfgNode call | call.getCall().receiverImplicitlyBorrowed()).getReceiver(), //
471471
getPostUpdateReverseStep(any(PostUpdateNode n).getPreUpdateNode().asExpr(), _)
472472
]
473473
} or

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,15 @@ private module Cached {
34823482
/** Holds if `receiver` is the receiver of a method call with an implicit dereference. */
34833483
cached
34843484
predicate receiverHasImplicitDeref(AstNode receiver) {
3485-
none() // todo
3485+
exists(MethodCall mc |
3486+
exists(resolveMethodCallTarget(MkMethodCallDerefChainRef(mc, ".ref;"))) and
3487+
receiver = mc.getArgument(CallImpl::TSelfArgumentPosition())
3488+
)
3489+
or
3490+
exists(Op op |
3491+
op.(Call).implicitBorrowAt(CallImpl::TSelfArgumentPosition(), true) and
3492+
receiver = op.getOperand(0)
3493+
)
34863494
// exists(MethodCallExprMatchingInput::Access a, MethodCallExprMatchingInput::AccessPosition apos |
34873495
// apos.getArgumentPosition().isSelf() and
34883496
// apos.isBorrowed(_) and
@@ -3495,7 +3503,10 @@ private module Cached {
34953503
/** Holds if `receiver` is the receiver of a method call with an implicit borrow. */
34963504
cached
34973505
predicate receiverHasImplicitBorrow(AstNode receiver) {
3498-
none() // todo
3506+
exists(MethodCall mc |
3507+
exists(resolveMethodCallTarget(MkMethodCallDerefChainRef(mc, ";ref"))) and
3508+
receiver = mc.getArgument(CallImpl::TSelfArgumentPosition())
3509+
)
34993510
// exists(MethodCallExprMatchingInput::Access a, MethodCallExprMatchingInput::AccessPosition apos |
35003511
// apos.getArgumentPosition().isSelf() and
35013512
// apos.isBorrowed(_) and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ subpaths
400400
| 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] |
401401
| 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] |
402402
testFailures
403+
| main.rs:277:14:277:58 | //... | Missing result: hasTaintFlow=28 |
403404
#select
404405
| main.rs:18:10:18:10 | a | main.rs:13:5:13:13 | source(...) | main.rs:18:10:18:10 | a | $@ | main.rs:13:5:13:13 | source(...) | source(...) |
405406
| main.rs:39:10:39:21 | a.get_data() | main.rs:38:23:38:31 | source(...) | main.rs:39:10:39:21 | a.get_data() | $@ | main.rs:38:23:38:31 | source(...) | source(...) |

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
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:228:10:228:14 | * ... | main.rs:235:5:237:5 | fn deref |
63-
| main.rs:236:11:236:15 | * ... | main.rs:235:5:237:5 | fn deref |
6462
| main.rs:242:28:242:36 | source(...) | main.rs:1:1:3:1 | fn source |
6563
| main.rs:244:13:244:17 | ... + ... | main.rs:220:5:223:5 | fn add |
6664
| main.rs:245:5:245:17 | sink(...) | main.rs:5:1:7:1 | fn sink |

0 commit comments

Comments
 (0)