Skip to content

Commit ddbcdcb

Browse files
authored
Merge pull request github#11160 from RasmusWL/dataflow-consistency-read-store
DataFlow: Add read/store stepIsLocal consistency checks
2 parents 7b6cb70 + 88f703a commit ddbcdcb

File tree

34 files changed

+196
-0
lines changed

34 files changed

+196
-0
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ uniqueNodeToString
66
missingToString
77
parameterCallable
88
localFlowIsLocal
9+
readStepIsLocal
10+
storeStepIsLocal
911
compatibleTypesReflexive
1012
unreachableNodeCCtx
1113
localCallNodes

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ uniqueNodeToString
2121
missingToString
2222
parameterCallable
2323
localFlowIsLocal
24+
readStepIsLocal
25+
storeStepIsLocal
2426
compatibleTypesReflexive
2527
unreachableNodeCCtx
2628
localCallNodes

cpp/ql/test/library-tests/dataflow/fields/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ uniqueNodeToString
1212
missingToString
1313
parameterCallable
1414
localFlowIsLocal
15+
readStepIsLocal
16+
storeStepIsLocal
1517
compatibleTypesReflexive
1618
unreachableNodeCCtx
1719
localCallNodes

cpp/ql/test/library-tests/dataflow/fields/dataflow-ir-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ uniqueNodeToString
1515
missingToString
1616
parameterCallable
1717
localFlowIsLocal
18+
readStepIsLocal
19+
storeStepIsLocal
1820
compatibleTypesReflexive
1921
unreachableNodeCCtx
2022
localCallNodes

cpp/ql/test/library-tests/syntax-zoo/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ uniqueNodeToString
5252
missingToString
5353
parameterCallable
5454
localFlowIsLocal
55+
readStepIsLocal
56+
storeStepIsLocal
5557
compatibleTypesReflexive
5658
unreachableNodeCCtx
5759
localCallNodes

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,8 @@ uniqueNodeToString
14631463
missingToString
14641464
parameterCallable
14651465
localFlowIsLocal
1466+
readStepIsLocal
1467+
storeStepIsLocal
14661468
compatibleTypesReflexive
14671469
unreachableNodeCCtx
14681470
localCallNodes

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

0 commit comments

Comments
 (0)