Skip to content

Commit b84adec

Browse files
authored
Merge pull request #18568 from paldepind/rust-container
Rust: Change array element content type into a general collection element content type
2 parents 10f5513 + e7ad091 commit b84adec

File tree

9 files changed

+119
-116
lines changed

9 files changed

+119
-116
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,12 +759,15 @@ final class ReferenceContent extends Content, TReferenceContent {
759759
}
760760

761761
/**
762-
* An element in an array.
762+
* An element in a collection where we do not track the specific collection
763+
* type nor the placement of the element in the collection. Therefore the
764+
* collection should be one where the elements are reasonably homogeneous,
765+
* i.e., if one is tainted all elements are considered tainted.
766+
*
767+
* Examples include the elements of a set, array, vector, or stack.
763768
*/
764-
final class ArrayElementContent extends Content, TArrayElement {
765-
ArrayElementContent() { this = TArrayElement() }
766-
767-
override string toString() { result = "array[]" }
769+
final class ElementContent extends Content, TElementContent {
770+
override string toString() { result = "element" }
768771
}
769772

770773
/**
@@ -1086,19 +1089,19 @@ module RustDataFlow implements InputSig<Location> {
10861089
)
10871090
or
10881091
exists(IndexExprCfgNode arr |
1089-
c instanceof ArrayElementContent and
1092+
c instanceof ElementContent and
10901093
node1.asExpr() = arr.getBase() and
10911094
node2.asExpr() = arr
10921095
)
10931096
or
10941097
exists(ForExprCfgNode for |
1095-
c instanceof ArrayElementContent and
1098+
c instanceof ElementContent and
10961099
node1.asExpr() = for.getIterable() and
10971100
node2.asPat() = for.getPat()
10981101
)
10991102
or
11001103
exists(SlicePatCfgNode pat |
1101-
c instanceof ArrayElementContent and
1104+
c instanceof ElementContent and
11021105
node1.asPat() = pat and
11031106
node2.asPat() = pat.getAPat()
11041107
)
@@ -1178,7 +1181,7 @@ module RustDataFlow implements InputSig<Location> {
11781181
node2.asExpr() = tuple
11791182
)
11801183
or
1181-
c instanceof ArrayElementContent and
1184+
c instanceof ElementContent and
11821185
node1.asExpr() =
11831186
[
11841187
node2.asExpr().(ArrayRepeatExprCfgNode).getRepeatOperand(),
@@ -1188,7 +1191,7 @@ module RustDataFlow implements InputSig<Location> {
11881191
tupleAssignment(node1, node2.(PostUpdateNode).getPreUpdateNode(), c)
11891192
or
11901193
exists(AssignmentExprCfgNode assignment, IndexExprCfgNode index |
1191-
c instanceof ArrayElementContent and
1194+
c instanceof ElementContent and
11921195
assignment.getLhs() = index and
11931196
node1.asExpr() = assignment.getRhs() and
11941197
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = index.getBase()
@@ -1561,7 +1564,7 @@ private module Cached {
15611564
TVariantFieldContent(VariantCanonicalPath v, string field) {
15621565
field = v.getVariant().getFieldList().(RecordFieldList).getAField().getName().getText()
15631566
} or
1564-
TArrayElement() or
1567+
TElementContent() or
15651568
TTuplePositionContent(int pos) {
15661569
pos in [0 .. max([
15671570
any(TuplePat pat).getNumberOfFields(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ module Input implements InputSig<Location, RustDataFlow> {
7979
arg = s.getExtendedCanonicalPath() + "::" + field
8080
)
8181
or
82-
result = "ArrayElement" and
83-
c = TArrayElement() and
82+
result = "Element" and
83+
c = TElementContent() and
8484
arg = ""
8585
or
8686
exists(int pos |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* - `Parameter[n]`: the `n`-th parameter of a callback. May be a range of form `x..y` (inclusive)
2929
* and/or a comma-separated list.
3030
* - `ReturnValue`: the value returned by a function call.
31-
* - `ArrayElement`: an element of an array.
31+
* - `Element`: an element in a collection.
3232
* - `Variant[v::f]`: field `f` of the variant with canonical path `v`, for example
3333
* `Variant[crate::ihex::Record::Data::value]`.
3434
* - `Variant[v(i)]`: position `i` inside the variant with canonical path `v`, for example

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
4444
// source is a collection.
4545
exists(SingletonContentSet cs |
4646
RustDataFlow::readStep(pred, cs, succ) and
47-
cs.getContent() instanceof ArrayElementContent
47+
cs.getContent() instanceof ElementContent
4848
)
4949
or
5050
exists(FormatArgsExprCfgNode format | succ.asExpr() = format |
@@ -64,7 +64,7 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
6464
predicate defaultImplicitTaintRead(Node::Node node, ContentSet cs) {
6565
exists(node) and
6666
exists(Content c | c = cs.(SingletonContentSet).getContent() |
67-
c instanceof ArrayElementContent or
67+
c instanceof ElementContent or
6868
c instanceof ReferenceContent
6969
)
7070
}

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -526,26 +526,26 @@ storeStep
526526
| main.rs:306:41:306:41 | 2 | D | main.rs:306:14:306:43 | ...::D {...} |
527527
| main.rs:324:18:324:27 | source(...) | C | main.rs:323:14:325:5 | C {...} |
528528
| main.rs:326:27:326:27 | 2 | D | main.rs:326:14:326:29 | D {...} |
529-
| main.rs:344:17:344:17 | 1 | array[] | main.rs:344:16:344:33 | [...] |
530-
| main.rs:344:20:344:20 | 2 | array[] | main.rs:344:16:344:33 | [...] |
531-
| main.rs:344:23:344:32 | source(...) | array[] | main.rs:344:16:344:33 | [...] |
532-
| main.rs:348:17:348:26 | source(...) | array[] | main.rs:348:16:348:31 | [...; 10] |
533-
| main.rs:352:17:352:17 | 1 | array[] | main.rs:352:16:352:24 | [...] |
534-
| main.rs:352:20:352:20 | 2 | array[] | main.rs:352:16:352:24 | [...] |
535-
| main.rs:352:23:352:23 | 3 | array[] | main.rs:352:16:352:24 | [...] |
536-
| main.rs:358:17:358:17 | 1 | array[] | main.rs:358:16:358:33 | [...] |
537-
| main.rs:358:20:358:20 | 2 | array[] | main.rs:358:16:358:33 | [...] |
538-
| main.rs:358:23:358:32 | source(...) | array[] | main.rs:358:16:358:33 | [...] |
539-
| main.rs:363:17:363:17 | 1 | array[] | main.rs:363:16:363:24 | [...] |
540-
| main.rs:363:20:363:20 | 2 | array[] | main.rs:363:16:363:24 | [...] |
541-
| main.rs:363:23:363:23 | 3 | array[] | main.rs:363:16:363:24 | [...] |
542-
| main.rs:370:17:370:17 | 1 | array[] | main.rs:370:16:370:33 | [...] |
543-
| main.rs:370:20:370:20 | 2 | array[] | main.rs:370:16:370:33 | [...] |
544-
| main.rs:370:23:370:32 | source(...) | array[] | main.rs:370:16:370:33 | [...] |
545-
| main.rs:381:24:381:24 | 1 | array[] | main.rs:381:23:381:31 | [...] |
546-
| main.rs:381:27:381:27 | 2 | array[] | main.rs:381:23:381:31 | [...] |
547-
| main.rs:381:30:381:30 | 3 | array[] | main.rs:381:23:381:31 | [...] |
548-
| main.rs:384:18:384:27 | source(...) | array[] | main.rs:384:5:384:11 | [post] mut_arr |
529+
| main.rs:344:17:344:17 | 1 | element | main.rs:344:16:344:33 | [...] |
530+
| main.rs:344:20:344:20 | 2 | element | main.rs:344:16:344:33 | [...] |
531+
| main.rs:344:23:344:32 | source(...) | element | main.rs:344:16:344:33 | [...] |
532+
| main.rs:348:17:348:26 | source(...) | element | main.rs:348:16:348:31 | [...; 10] |
533+
| main.rs:352:17:352:17 | 1 | element | main.rs:352:16:352:24 | [...] |
534+
| main.rs:352:20:352:20 | 2 | element | main.rs:352:16:352:24 | [...] |
535+
| main.rs:352:23:352:23 | 3 | element | main.rs:352:16:352:24 | [...] |
536+
| main.rs:358:17:358:17 | 1 | element | main.rs:358:16:358:33 | [...] |
537+
| main.rs:358:20:358:20 | 2 | element | main.rs:358:16:358:33 | [...] |
538+
| main.rs:358:23:358:32 | source(...) | element | main.rs:358:16:358:33 | [...] |
539+
| main.rs:363:17:363:17 | 1 | element | main.rs:363:16:363:24 | [...] |
540+
| main.rs:363:20:363:20 | 2 | element | main.rs:363:16:363:24 | [...] |
541+
| main.rs:363:23:363:23 | 3 | element | main.rs:363:16:363:24 | [...] |
542+
| main.rs:370:17:370:17 | 1 | element | main.rs:370:16:370:33 | [...] |
543+
| main.rs:370:20:370:20 | 2 | element | main.rs:370:16:370:33 | [...] |
544+
| main.rs:370:23:370:32 | source(...) | element | main.rs:370:16:370:33 | [...] |
545+
| main.rs:381:24:381:24 | 1 | element | main.rs:381:23:381:31 | [...] |
546+
| main.rs:381:27:381:27 | 2 | element | main.rs:381:23:381:31 | [...] |
547+
| main.rs:381:30:381:30 | 3 | element | main.rs:381:23:381:31 | [...] |
548+
| main.rs:384:18:384:27 | source(...) | element | main.rs:384:5:384:11 | [post] mut_arr |
549549
| main.rs:396:35:396:61 | default_name | captured default_name | main.rs:396:35:396:61 | \|...\| ... |
550550
| main.rs:418:27:418:27 | 0 | Some | main.rs:418:22:418:28 | Some(...) |
551551
readStep
@@ -612,20 +612,20 @@ readStep
612612
| main.rs:332:28:332:43 | D {...} | D | main.rs:332:41:332:41 | n |
613613
| main.rs:335:9:335:24 | C {...} | C | main.rs:335:22:335:22 | n |
614614
| main.rs:336:9:336:24 | D {...} | D | main.rs:336:22:336:22 | n |
615-
| main.rs:345:14:345:17 | arr1 | array[] | main.rs:345:14:345:20 | arr1[2] |
616-
| main.rs:349:14:349:17 | arr2 | array[] | main.rs:349:14:349:20 | arr2[4] |
617-
| main.rs:353:14:353:17 | arr3 | array[] | main.rs:353:14:353:20 | arr3[2] |
618-
| main.rs:359:15:359:18 | arr1 | array[] | main.rs:359:9:359:10 | n1 |
619-
| main.rs:364:15:364:18 | arr2 | array[] | main.rs:364:9:364:10 | n2 |
620-
| main.rs:372:9:372:17 | SlicePat | array[] | main.rs:372:10:372:10 | a |
621-
| main.rs:372:9:372:17 | SlicePat | array[] | main.rs:372:13:372:13 | b |
622-
| main.rs:372:9:372:17 | SlicePat | array[] | main.rs:372:16:372:16 | c |
623-
| main.rs:382:10:382:16 | mut_arr | array[] | main.rs:382:10:382:19 | mut_arr[1] |
624-
| main.rs:384:5:384:11 | mut_arr | array[] | main.rs:384:5:384:14 | mut_arr[1] |
625-
| main.rs:385:13:385:19 | mut_arr | array[] | main.rs:385:13:385:22 | mut_arr[1] |
626-
| main.rs:387:10:387:16 | mut_arr | array[] | main.rs:387:10:387:19 | mut_arr[0] |
615+
| main.rs:345:14:345:17 | arr1 | element | main.rs:345:14:345:20 | arr1[2] |
616+
| main.rs:349:14:349:17 | arr2 | element | main.rs:349:14:349:20 | arr2[4] |
617+
| main.rs:353:14:353:17 | arr3 | element | main.rs:353:14:353:20 | arr3[2] |
618+
| main.rs:359:15:359:18 | arr1 | element | main.rs:359:9:359:10 | n1 |
619+
| main.rs:364:15:364:18 | arr2 | element | main.rs:364:9:364:10 | n2 |
620+
| main.rs:372:9:372:17 | SlicePat | element | main.rs:372:10:372:10 | a |
621+
| main.rs:372:9:372:17 | SlicePat | element | main.rs:372:13:372:13 | b |
622+
| main.rs:372:9:372:17 | SlicePat | element | main.rs:372:16:372:16 | c |
623+
| main.rs:382:10:382:16 | mut_arr | element | main.rs:382:10:382:19 | mut_arr[1] |
624+
| main.rs:384:5:384:11 | mut_arr | element | main.rs:384:5:384:14 | mut_arr[1] |
625+
| main.rs:385:13:385:19 | mut_arr | element | main.rs:385:13:385:22 | mut_arr[1] |
626+
| main.rs:387:10:387:16 | mut_arr | element | main.rs:387:10:387:19 | mut_arr[0] |
627627
| main.rs:394:7:394:18 | TuplePat | tuple.0 | main.rs:394:8:394:11 | cond |
628628
| main.rs:394:7:394:18 | TuplePat | tuple.1 | main.rs:394:14:394:17 | name |
629-
| main.rs:394:23:394:27 | names | array[] | main.rs:394:7:394:18 | TuplePat |
629+
| main.rs:394:23:394:27 | names | element | main.rs:394:7:394:18 | TuplePat |
630630
| main.rs:396:35:396:61 | [post] \|...\| ... | captured default_name | main.rs:396:35:396:61 | [post] default_name |
631631
| main.rs:396:38:396:49 | this | captured default_name | main.rs:396:38:396:49 | default_name |

0 commit comments

Comments
 (0)