Skip to content

Commit 8b424d1

Browse files
authored
Merge pull request github#10505 from hvitved/dataflow/viable-impl-in-ctx-consistency
Data flow: Guard against `viableImplInCallContext` not being a subset of `viableCallable`
2 parents cee0e8e + 914c711 commit 8b424d1

File tree

43 files changed

+175
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+175
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ private module Cached {
709709
*/
710710
pragma[nomagic]
711711
private DataFlowCallable viableImplInCallContextExt(DataFlowCall call, DataFlowCall ctx) {
712-
result = viableImplInCallContext(call, ctx)
712+
result = viableImplInCallContext(call, ctx) and
713+
result = viableCallable(call)
713714
or
714715
result = viableCallableLambda(call, TDataFlowCallSome(ctx))
715716
or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ module Consistency {
3838

3939
/** Holds if `n` should be excluded from the consistency test `uniquePostUpdate`. */
4040
predicate uniquePostUpdateExclude(Node n) { none() }
41+
42+
/** Holds if `(call, ctx)` should be excluded from the consistency test `viableImplInCallContextTooLargeExclude`. */
43+
predicate viableImplInCallContextTooLargeExclude(
44+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
45+
) {
46+
none()
47+
}
4148
}
4249

4350
private class RelevantNode extends Node {
@@ -217,4 +224,12 @@ module Consistency {
217224
not any(ConsistencyConfiguration c).postWithInFlowExclude(n) and
218225
msg = "PostUpdateNode should not be the target of local flow."
219226
}
227+
228+
query predicate viableImplInCallContextTooLarge(
229+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
230+
) {
231+
callable = viableImplInCallContext(call, ctx) and
232+
not callable = viableCallable(call) and
233+
not any(ConsistencyConfiguration c).viableImplInCallContextTooLargeExclude(call, ctx, callable)
234+
}
220235
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ private module Cached {
709709
*/
710710
pragma[nomagic]
711711
private DataFlowCallable viableImplInCallContextExt(DataFlowCall call, DataFlowCall ctx) {
712-
result = viableImplInCallContext(call, ctx)
712+
result = viableImplInCallContext(call, ctx) and
713+
result = viableCallable(call)
713714
or
714715
result = viableCallableLambda(call, TDataFlowCallSome(ctx))
715716
or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ module Consistency {
3838

3939
/** Holds if `n` should be excluded from the consistency test `uniquePostUpdate`. */
4040
predicate uniquePostUpdateExclude(Node n) { none() }
41+
42+
/** Holds if `(call, ctx)` should be excluded from the consistency test `viableImplInCallContextTooLargeExclude`. */
43+
predicate viableImplInCallContextTooLargeExclude(
44+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
45+
) {
46+
none()
47+
}
4148
}
4249

4350
private class RelevantNode extends Node {
@@ -217,4 +224,12 @@ module Consistency {
217224
not any(ConsistencyConfiguration c).postWithInFlowExclude(n) and
218225
msg = "PostUpdateNode should not be the target of local flow."
219226
}
227+
228+
query predicate viableImplInCallContextTooLarge(
229+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
230+
) {
231+
callable = viableImplInCallContext(call, ctx) and
232+
not callable = viableCallable(call) and
233+
not any(ConsistencyConfiguration c).viableImplInCallContextTooLargeExclude(call, ctx, callable)
234+
}
220235
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ private module Cached {
709709
*/
710710
pragma[nomagic]
711711
private DataFlowCallable viableImplInCallContextExt(DataFlowCall call, DataFlowCall ctx) {
712-
result = viableImplInCallContext(call, ctx)
712+
result = viableImplInCallContext(call, ctx) and
713+
result = viableCallable(call)
713714
or
714715
result = viableCallableLambda(call, TDataFlowCallSome(ctx))
715716
or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ module Consistency {
3838

3939
/** Holds if `n` should be excluded from the consistency test `uniquePostUpdate`. */
4040
predicate uniquePostUpdateExclude(Node n) { none() }
41+
42+
/** Holds if `(call, ctx)` should be excluded from the consistency test `viableImplInCallContextTooLargeExclude`. */
43+
predicate viableImplInCallContextTooLargeExclude(
44+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
45+
) {
46+
none()
47+
}
4148
}
4249

4350
private class RelevantNode extends Node {
@@ -217,4 +224,12 @@ module Consistency {
217224
not any(ConsistencyConfiguration c).postWithInFlowExclude(n) and
218225
msg = "PostUpdateNode should not be the target of local flow."
219226
}
227+
228+
query predicate viableImplInCallContextTooLarge(
229+
DataFlowCall call, DataFlowCall ctx, DataFlowCallable callable
230+
) {
231+
callable = viableImplInCallContext(call, ctx) and
232+
not callable = viableCallable(call) and
233+
not any(ConsistencyConfiguration c).viableImplInCallContextTooLargeExclude(call, ctx, callable)
234+
}
220235
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ postWithInFlow
8787
| test.cpp:465:3:465:4 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
8888
| test.cpp:465:4:465:4 | p [inner post update] | PostUpdateNode should not be the target of local flow. |
8989
| test.cpp:470:22:470:22 | x [inner post update] | PostUpdateNode should not be the target of local flow. |
90+
viableImplInCallContextTooLarge

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,4 @@ postWithInFlow
627627
| true_upon_entry.cpp:98:7:98:7 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
628628
| true_upon_entry.cpp:101:18:101:18 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
629629
| true_upon_entry.cpp:102:5:102:5 | x [post update] | PostUpdateNode should not be the target of local flow. |
630+
viableImplInCallContextTooLarge

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ postWithInFlow
155155
| simple.cpp:92:7:92:7 | i [post update] | PostUpdateNode should not be the target of local flow. |
156156
| struct_init.c:24:11:24:12 | ab [inner post update] | PostUpdateNode should not be the target of local flow. |
157157
| struct_init.c:36:17:36:24 | nestedAB [inner post update] | PostUpdateNode should not be the target of local flow. |
158+
viableImplInCallContextTooLarge

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,3 +1323,4 @@ postWithInFlow
13231323
| struct_init.c:46:16:46:24 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
13241324
| struct_init.c:46:16:46:24 | pointerAB [post update] | PostUpdateNode should not be the target of local flow. |
13251325
| struct_init.c:46:16:46:24 | pointerAB [post update] | PostUpdateNode should not be the target of local flow. |
1326+
viableImplInCallContextTooLarge

0 commit comments

Comments
 (0)