Skip to content

Commit a9d76cb

Browse files
committed
Dataflow: Add consistency checks for toString and ___location.
1 parent e97c72c commit a9d76cb

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ module Consistency {
5555
)
5656
}
5757

58+
query predicate uniqueNodeLocation(Node n, string msg) {
59+
exists(int c |
60+
c =
61+
count(string filepath, int startline, int startcolumn, int endline, int endcolumn |
62+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
63+
) and
64+
c != 1 and
65+
msg = "Node should have one ___location but has " + c + "."
66+
)
67+
}
68+
69+
query predicate missingLocation(string msg) {
70+
exists(int c |
71+
c =
72+
strictcount(Node n |
73+
not exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
74+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
75+
)
76+
) and
77+
msg = "Nodes without ___location: " + c
78+
)
79+
}
80+
81+
query predicate uniqueNodeToString(Node n, string msg) {
82+
exists(int c |
83+
c = count(n.toString()) and
84+
c != 1 and
85+
msg = "Node should have one toString but has " + c + "."
86+
)
87+
}
88+
89+
query predicate missingToString(string msg) {
90+
exists(int c |
91+
c = strictcount(Node n | not exists(n.toString())) and
92+
msg = "Nodes without toString: " + c
93+
)
94+
}
95+
5896
query predicate parameterCallable(ParameterNode p, string msg) {
5997
exists(DataFlowCallable c | p.isParameterOf(c, _) and c != p.getEnclosingCallable()) and
6098
msg = "Callable mismatch for parameter."

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ module Consistency {
5555
)
5656
}
5757

58+
query predicate uniqueNodeLocation(Node n, string msg) {
59+
exists(int c |
60+
c =
61+
count(string filepath, int startline, int startcolumn, int endline, int endcolumn |
62+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
63+
) and
64+
c != 1 and
65+
msg = "Node should have one ___location but has " + c + "."
66+
)
67+
}
68+
69+
query predicate missingLocation(string msg) {
70+
exists(int c |
71+
c =
72+
strictcount(Node n |
73+
not exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
74+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
75+
)
76+
) and
77+
msg = "Nodes without ___location: " + c
78+
)
79+
}
80+
81+
query predicate uniqueNodeToString(Node n, string msg) {
82+
exists(int c |
83+
c = count(n.toString()) and
84+
c != 1 and
85+
msg = "Node should have one toString but has " + c + "."
86+
)
87+
}
88+
89+
query predicate missingToString(string msg) {
90+
exists(int c |
91+
c = strictcount(Node n | not exists(n.toString())) and
92+
msg = "Nodes without toString: " + c
93+
)
94+
}
95+
5896
query predicate parameterCallable(ParameterNode p, string msg) {
5997
exists(DataFlowCallable c | p.isParameterOf(c, _) and c != p.getEnclosingCallable()) and
6098
msg = "Callable mismatch for parameter."

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ module Consistency {
5555
)
5656
}
5757

58+
query predicate uniqueNodeLocation(Node n, string msg) {
59+
exists(int c |
60+
c =
61+
count(string filepath, int startline, int startcolumn, int endline, int endcolumn |
62+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
63+
) and
64+
c != 1 and
65+
msg = "Node should have one ___location but has " + c + "."
66+
)
67+
}
68+
69+
query predicate missingLocation(string msg) {
70+
exists(int c |
71+
c =
72+
strictcount(Node n |
73+
not exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
74+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
75+
)
76+
) and
77+
msg = "Nodes without ___location: " + c
78+
)
79+
}
80+
81+
query predicate uniqueNodeToString(Node n, string msg) {
82+
exists(int c |
83+
c = count(n.toString()) and
84+
c != 1 and
85+
msg = "Node should have one toString but has " + c + "."
86+
)
87+
}
88+
89+
query predicate missingToString(string msg) {
90+
exists(int c |
91+
c = strictcount(Node n | not exists(n.toString())) and
92+
msg = "Nodes without toString: " + c
93+
)
94+
}
95+
5896
query predicate parameterCallable(ParameterNode p, string msg) {
5997
exists(DataFlowCallable c | p.isParameterOf(c, _) and c != p.getEnclosingCallable()) and
6098
msg = "Callable mismatch for parameter."

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ module Consistency {
5555
)
5656
}
5757

58+
query predicate uniqueNodeLocation(Node n, string msg) {
59+
exists(int c |
60+
c =
61+
count(string filepath, int startline, int startcolumn, int endline, int endcolumn |
62+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
63+
) and
64+
c != 1 and
65+
msg = "Node should have one ___location but has " + c + "."
66+
)
67+
}
68+
69+
query predicate missingLocation(string msg) {
70+
exists(int c |
71+
c =
72+
strictcount(Node n |
73+
not exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
74+
n.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
75+
)
76+
) and
77+
msg = "Nodes without ___location: " + c
78+
)
79+
}
80+
81+
query predicate uniqueNodeToString(Node n, string msg) {
82+
exists(int c |
83+
c = count(n.toString()) and
84+
c != 1 and
85+
msg = "Node should have one toString but has " + c + "."
86+
)
87+
}
88+
89+
query predicate missingToString(string msg) {
90+
exists(int c |
91+
c = strictcount(Node n | not exists(n.toString())) and
92+
msg = "Nodes without toString: " + c
93+
)
94+
}
95+
5896
query predicate parameterCallable(ParameterNode p, string msg) {
5997
exists(DataFlowCallable c | p.isParameterOf(c, _) and c != p.getEnclosingCallable()) and
6098
msg = "Callable mismatch for parameter."

0 commit comments

Comments
 (0)