Skip to content

Commit 8abfb23

Browse files
committed
wip2
1 parent cea8d5f commit 8abfb23

File tree

7 files changed

+77
-65
lines changed

7 files changed

+77
-65
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ private module Input implements InputSig<Location, RustDataFlow> {
1919
predicate postWithInFlowExclude(RustDataFlow::Node n) {
2020
n instanceof Node::FlowSummaryNode
2121
or
22-
n.(Node::PostUpdateNode).getPreUpdateNode().asExpr() = getPostUpdateReverseStep(_, _)
23-
or
2422
FlowSummaryImpl::Private::Steps::sourceLocalStep(_, n, _)
2523
}
2624

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ module LocalFlow {
275275
or
276276
nodeFrom.asPat().(OrPat).getAPat() = nodeTo.asPat()
277277
or
278+
// or
279+
// // x.foo -> (&x).foo
280+
// // [post] &x -> [post] x
281+
// //
282+
// // x.foo -> (*x).foo
283+
// // [post] *x -> [post] x
284+
// nodeFrom.(PostUpdateNode).getPreUpdateNode().(DerefBorrowNode).getNode() =
285+
// nodeTo.(PostUpdateNode).getPreUpdateNode().asExpr()
286+
// or
287+
// // *x -> *Deref::deref(&x)
288+
// nodeFrom.(PostUpdateNode).getPreUpdateNode().(DerefOutNode).getDerefExpr() =
289+
// nodeTo.(PostUpdateNode).getPreUpdateNode().asExpr()
278290
nodeTo.(PostUpdateNode).getPreUpdateNode().asExpr() =
279291
getPostUpdateReverseStep(nodeFrom.(PostUpdateNode).getPreUpdateNode().asExpr(), true)
280292
}
@@ -721,10 +733,10 @@ module RustDataFlow implements InputSig<Location> {
721733
VariableCapture::storeStep(node1, c, node2)
722734
or
723735
implicitBorrow(node1, node2, c)
724-
or
725-
// A store step dual to the read step for implicit dereferences.
726-
implicitDeref(node2.(PostUpdateNode).getPreUpdateNode(),
727-
node1.(PostUpdateNode).getPreUpdateNode(), c)
736+
// or
737+
// // A store step dual to the read step for implicit dereferences.
738+
// implicitDeref(node2.(PostUpdateNode).getPreUpdateNode(),
739+
// node1.(PostUpdateNode).getPreUpdateNode(), c)
728740
}
729741

730742
/**

rust/ql/lib/codeql/rust/frameworks/stdlib/alloc.model.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extensions:
2424
extensible: summaryModel
2525
data:
2626
# Box
27-
- ["<alloc::boxed::Box as core::ops::deref::Deref>::deref", "Argument[self].Field[alloc::boxed::Box(0)]", "ReturnValue.Reference", "value", "manual"]
27+
- ["<alloc::boxed::Box as core::ops::deref::Deref>::deref", "Argument[self].Reference.Field[alloc::boxed::Box(0)]", "ReturnValue.Reference", "value", "manual"]
2828
- ["<alloc::boxed::Box>::pin", "Argument[0]", "ReturnValue.Field[core::pin::Pin::pointer].Field[alloc::boxed::Box(0)]", "value", "manual"]
2929
- ["<alloc::boxed::Box>::new", "Argument[0]", "ReturnValue.Field[alloc::boxed::Box(0)]", "value", "manual"]
3030
- ["<alloc::boxed::Box>::into_pin", "Argument[0]", "ReturnValue.Field[core::pin::Pin::pointer]", "value", "manual"]

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,8 +3563,8 @@ private module Debug {
35633563
Locatable getRelevantLocatable() {
35643564
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
35653565
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
3566-
filepath.matches("%/sqlx.rs") and
3567-
startline = [56 .. 60]
3566+
filepath.matches("%/main.rs") and
3567+
startline = 116
35683568
)
35693569
}
35703570

@@ -3573,9 +3573,10 @@ private module Debug {
35733573
result = inferType(n, path)
35743574
}
35753575

3576-
Addressable debugResolveCallTarget(Call c) {
3576+
Addressable debugResolveCallTarget(Call c, string can) {
35773577
c = getRelevantLocatable() and
3578-
result = resolveCallTarget(c)
3578+
result = resolveCallTarget(c) and
3579+
can = result.getCanonicalPath()
35793580
}
35803581

35813582
predicate debugConditionSatisfiesConstraint(

rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,8 @@ localStep
825825
| main.rs:616:36:616:41 | [post] MacroExpr | main.rs:616:36:616:39 | [post] ...::new(...) |
826826
readStep
827827
| main.rs:50:9:50:15 | Some(...) | {EXTERNAL LOCATION} | Some | main.rs:50:14:50:14 | _ |
828+
| main.rs:116:10:116:11 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:116:10:116:11 | * ... |
828829
| main.rs:116:11:116:11 | [post] i [borrowed] | file://:0:0:0:0 | &ref | main.rs:116:11:116:11 | [post] i |
829-
| main.rs:116:11:116:11 | i | file://:0:0:0:0 | &ref | main.rs:116:10:116:11 | * ... |
830830
| main.rs:124:10:124:10 | a | file://:0:0:0:0 | tuple.0 | main.rs:124:10:124:12 | a.0 |
831831
| main.rs:125:10:125:10 | a | file://:0:0:0:0 | tuple.1 | main.rs:125:10:125:12 | a.1 |
832832
| main.rs:130:9:130:20 | TuplePat | file://:0:0:0:0 | tuple.0 | main.rs:130:10:130:11 | a0 |
@@ -934,30 +934,30 @@ readStep
934934
| main.rs:506:13:506:13 | [post] a [borrowed] | file://:0:0:0:0 | &ref | main.rs:506:13:506:13 | [post] a |
935935
| main.rs:519:10:519:11 | [post] vs [borrowed] | file://:0:0:0:0 | &ref | main.rs:519:10:519:11 | [post] vs |
936936
| main.rs:519:10:519:11 | vs | file://:0:0:0:0 | element | main.rs:519:10:519:14 | vs[0] |
937-
| main.rs:520:11:520:35 | ... .unwrap() | file://:0:0:0:0 | &ref | main.rs:520:10:520:35 | * ... |
937+
| main.rs:520:10:520:35 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:520:10:520:35 | * ... |
938938
| main.rs:520:11:520:35 | [post] ... .unwrap() [borrowed] | file://:0:0:0:0 | &ref | main.rs:520:11:520:35 | [post] ... .unwrap() |
939-
| main.rs:521:11:521:35 | ... .unwrap() | file://:0:0:0:0 | &ref | main.rs:521:10:521:35 | * ... |
939+
| main.rs:521:10:521:35 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:521:10:521:35 | * ... |
940940
| main.rs:521:11:521:35 | [post] ... .unwrap() [borrowed] | file://:0:0:0:0 | &ref | main.rs:521:11:521:35 | [post] ... .unwrap() |
941941
| main.rs:523:14:523:15 | vs | file://:0:0:0:0 | element | main.rs:523:9:523:9 | v |
942942
| main.rs:526:9:526:10 | &... | file://:0:0:0:0 | &ref | main.rs:526:10:526:10 | v |
943943
| main.rs:526:15:526:23 | vs.iter() | file://:0:0:0:0 | element | main.rs:526:9:526:10 | &... |
944944
| main.rs:531:9:531:10 | &... | file://:0:0:0:0 | &ref | main.rs:531:10:531:10 | v |
945945
| main.rs:531:15:531:17 | vs2 | file://:0:0:0:0 | element | main.rs:531:9:531:10 | &... |
946+
| main.rs:535:28:535:29 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:535:28:535:29 | * ... |
946947
| main.rs:535:29:535:29 | [post] x [borrowed] | file://:0:0:0:0 | &ref | main.rs:535:29:535:29 | [post] x |
947-
| main.rs:535:29:535:29 | x | file://:0:0:0:0 | &ref | main.rs:535:28:535:29 | * ... |
948+
| main.rs:536:33:536:34 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:536:33:536:34 | * ... |
948949
| main.rs:536:34:536:34 | [post] x [borrowed] | file://:0:0:0:0 | &ref | main.rs:536:34:536:34 | [post] x |
949-
| main.rs:536:34:536:34 | x | file://:0:0:0:0 | &ref | main.rs:536:33:536:34 | * ... |
950950
| main.rs:538:14:538:27 | vs.into_iter() | file://:0:0:0:0 | element | main.rs:538:9:538:9 | v |
951951
| main.rs:544:10:544:15 | [post] vs_mut [borrowed] | file://:0:0:0:0 | &ref | main.rs:544:10:544:15 | [post] vs_mut |
952952
| main.rs:544:10:544:15 | vs_mut | file://:0:0:0:0 | element | main.rs:544:10:544:18 | vs_mut[0] |
953-
| main.rs:545:11:545:39 | ... .unwrap() | file://:0:0:0:0 | &ref | main.rs:545:10:545:39 | * ... |
953+
| main.rs:545:10:545:39 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:545:10:545:39 | * ... |
954954
| main.rs:545:11:545:39 | [post] ... .unwrap() [borrowed] | file://:0:0:0:0 | &ref | main.rs:545:11:545:39 | [post] ... .unwrap() |
955-
| main.rs:546:11:546:39 | ... .unwrap() | file://:0:0:0:0 | &ref | main.rs:546:10:546:39 | * ... |
955+
| main.rs:546:10:546:39 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:546:10:546:39 | * ... |
956956
| main.rs:546:11:546:39 | [post] ... .unwrap() [borrowed] | file://:0:0:0:0 | &ref | main.rs:546:11:546:39 | [post] ... .unwrap() |
957957
| main.rs:548:9:548:14 | &mut ... | file://:0:0:0:0 | &ref | main.rs:548:14:548:14 | v |
958958
| main.rs:548:19:548:35 | vs_mut.iter_mut() | file://:0:0:0:0 | element | main.rs:548:9:548:14 | &mut ... |
959+
| main.rs:562:10:562:15 | * ... [pre-dereferenced] | file://:0:0:0:0 | &ref | main.rs:562:10:562:15 | * ... |
959960
| main.rs:562:11:562:15 | [post] c_ref [borrowed] | file://:0:0:0:0 | &ref | main.rs:562:11:562:15 | [post] c_ref |
960-
| main.rs:562:11:562:15 | c_ref | file://:0:0:0:0 | &ref | main.rs:562:10:562:15 | * ... |
961961
storeStep
962962
| main.rs:116:11:116:11 | i | file://:0:0:0:0 | &ref | main.rs:116:11:116:11 | i [borrowed] |
963963
| main.rs:123:14:123:22 | source(...) | file://:0:0:0:0 | tuple.0 | main.rs:123:13:123:26 | TupleExpr |

0 commit comments

Comments
 (0)