Skip to content

Commit 9f79890

Browse files
committed
Data flow: Add consistency check for DataFlowCall::getEnclosingCallable
1 parent 720eed3 commit 9f79890

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-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
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

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
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module Consistency {
1818
/** Holds if `n` should be excluded from the consistency test `uniqueEnclosingCallable`. */
1919
predicate uniqueEnclosingCallableExclude(Node n) { none() }
2020

21+
/** Holds if `call` should be excluded from the consistency test `uniqueCallEnclosingCallable`. */
22+
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { none() }
23+
2124
/** Holds if `n` should be excluded from the consistency test `uniqueNodeLocation`. */
2225
predicate uniqueNodeLocationExclude(Node n) { none() }
2326

@@ -86,6 +89,15 @@ module Consistency {
8689
)
8790
}
8891

92+
query predicate uniqueCallEnclosingCallable(DataFlowCall call, string msg) {
93+
exists(int c |
94+
c = count(call.getEnclosingCallable()) and
95+
c != 1 and
96+
not any(ConsistencyConfiguration conf).uniqueCallEnclosingCallableExclude(call) and
97+
msg = "Call should have one enclosing callable but has " + c + "."
98+
)
99+
}
100+
89101
query predicate uniqueType(Node n, string msg) {
90102
exists(int c |
91103
n instanceof RelevantNode and

0 commit comments

Comments
 (0)