Skip to content

Commit a09e479

Browse files
committed
Java: Change relevantNode to a class, and add two more checks.
1 parent ce70b86 commit a09e479

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

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

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,28 @@ private import DataFlowImplSpecific::Public
88
private import TaintTrackingUtil
99

1010
module Consistency {
11-
private predicate relevantNode(Node n) {
12-
n instanceof ArgumentNode or
13-
n instanceof ParameterNode or
14-
n instanceof ReturnNode or
15-
n = getAnOutNode(_, _) or
16-
simpleLocalFlowStep(n, _) or
17-
simpleLocalFlowStep(_, n) or
18-
jumpStep(n, _) or
19-
jumpStep(_, n) or
20-
storeStep(n, _, _) or
21-
storeStep(_, _, n) or
22-
readStep(n, _, _) or
23-
readStep(_, _, n) or
24-
defaultAdditionalTaintStep(n, _) or
25-
defaultAdditionalTaintStep(_, n)
11+
private class RelevantNode extends Node {
12+
RelevantNode() {
13+
this instanceof ArgumentNode or
14+
this instanceof ParameterNode or
15+
this instanceof ReturnNode or
16+
this = getAnOutNode(_, _) or
17+
simpleLocalFlowStep(this, _) or
18+
simpleLocalFlowStep(_, this) or
19+
jumpStep(this, _) or
20+
jumpStep(_, this) or
21+
storeStep(this, _, _) or
22+
storeStep(_, _, this) or
23+
readStep(this, _, _) or
24+
readStep(_, _, this) or
25+
defaultAdditionalTaintStep(this, _) or
26+
defaultAdditionalTaintStep(_, this)
27+
}
2628
}
2729

2830
query predicate uniqueEnclosingCallable(Node n, string msg) {
2931
exists(int c |
30-
relevantNode(n) and
32+
n instanceof RelevantNode and
3133
c = count(n.getEnclosingCallable()) and
3234
c != 1 and
3335
if c > 1
@@ -38,7 +40,7 @@ module Consistency {
3840

3941
query predicate uniqueTypeBound(Node n, string msg) {
4042
exists(int c |
41-
relevantNode(n) and
43+
n instanceof RelevantNode and
4244
c = count(n.getTypeBound()) and
4345
c != 1 and
4446
if c > 1
@@ -49,7 +51,7 @@ module Consistency {
4951

5052
query predicate uniqueTypeRepr(Node n, string msg) {
5153
exists(int c |
52-
relevantNode(n) and
54+
n instanceof RelevantNode and
5355
c = count(getErasedRepr(n.getTypeBound())) and
5456
c != 1 and
5557
if c > 1
@@ -101,6 +103,21 @@ module Consistency {
101103
n.getPreUpdateNode() = n and msg = "PostUpdateNode should not equal its pre-update node."
102104
}
103105

106+
query predicate postHasUniquePre(PostUpdateNode n, string msg) {
107+
exists(int c |
108+
c = count(n.getPreUpdateNode()) and
109+
c != 1 and
110+
if c > 1
111+
then msg = "PostUpdateNode does not have unique pre-update node."
112+
else msg = "PostUpdateNode is missing a pre-update node."
113+
)
114+
}
115+
116+
query predicate uniquePostUpdate(Node n, string msg) {
117+
1 < strictcount(PostUpdateNode post | post.getPreUpdateNode() = n) and
118+
msg = "Node has multiple PostUpdateNodes."
119+
}
120+
104121
query predicate postIsInSameCallable(PostUpdateNode n, string msg) {
105122
n.getEnclosingCallable() != n.getPreUpdateNode().getEnclosingCallable() and
106123
msg = "PostUpdateNode does not share callable with its pre-update node."

0 commit comments

Comments
 (0)