Skip to content

Commit 634b679

Browse files
committed
Fix more compilation errors in tests
1 parent 06ef793 commit 634b679

13 files changed

Lines changed: 31 additions & 28 deletions

File tree

java/ql/consistency-queries/cfgDeadEnds.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import java
22

3-
// import semmle.code.java.ControlFlowGraph
43
predicate shouldBeDeadEnd(ExprParent n) {
54
n instanceof BreakStmt and n.getFile().isKotlinSourceFile() // TODO
65
or

java/ql/lib/semmle/code/java/controlflow/BasicBlocks.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ class BasicBlock extends ControlFlowNode {
6666
/** Holds if this basic block post-dominates `node`. (This is reflexive.) */
6767
predicate bbPostDominates(BasicBlock node) { bbPostDominates(this, node) }
6868
}
69+
70+
class ExitBlock extends BasicBlock {
71+
ExitBlock() { this.getLastNode() instanceof ControlFlow::ExitNode }
72+
}

java/ql/lib/semmle/code/java/controlflow/Paths.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ private predicate callAlwaysPerformsAction(Call call, ActionConfiguration conf)
4343
)
4444
}
4545

46-
private class ExitBlock extends BasicBlock {
47-
ExitBlock() { this.getLastNode() instanceof ControlFlow::ExitNode }
48-
}
49-
5046
/** Holds if an action dominates the exit of the callable. */
5147
private predicate actionDominatesExit(Callable callable, ActionConfiguration conf) {
5248
exists(ExitBlock exit |

java/ql/lib/semmle/code/java/security/PathSanitizer.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ private module ValidationMethod<DataFlow::guardChecksSig/3 validationGuard> {
2929
*/
3030
private predicate validationMethod(Method m, int arg) {
3131
exists(
32-
Guard g, SsaImplicitInit var, ControlFlowNode exit, ControlFlowNode normexit, boolean branch
32+
Guard g, SsaImplicitInit var, ControlFlow::ExitNode exit, ControlFlowNode normexit,
33+
boolean branch
3334
|
3435
validationGuard(g, var.getAUse(), branch) and
3536
var.isParameterDefinition(m.getParameter(arg)) and
36-
exit = m and
37+
exit.getEnclosingCallable() = m and
3738
normexit.getANormalSuccessor() = exit and
3839
1 = strictcount(ControlFlowNode n | n.getANormalSuccessor() = exit)
3940
|
40-
g.(ConditionNode).getABranchSuccessor(branch) = exit or
41+
exists(ConditionNode conditionNode |
42+
g = conditionNode.getCondition() and conditionNode.getABranchSuccessor(branch) = exit
43+
)
44+
or
4145
g.controls(normexit.getBasicBlock(), branch)
4246
)
4347
}

java/ql/src/Likely Bugs/Comparison/UselessComparisonTest.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ predicate uselessTest(ConditionNode s1, BinaryExpr test, boolean testIsTrue) {
3030
ConditionBlock cb, SsaVariable v, BinaryExpr cond, boolean condIsTrue, int k1, int k2,
3131
CompileTimeConstantExpr c1, CompileTimeConstantExpr c2
3232
|
33-
s1 = cond and
33+
s1.getCondition() = cond and
3434
cb.getCondition() = cond and
3535
cond.hasOperands(v.getAUse(), c1) and
3636
c1.getIntValue() = k1 and

java/ql/src/Likely Bugs/Concurrency/DoubleCheckedLockingWithInitRace.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
doubleCheckedLocking(if1, if2, sync, f) and
3737
a.getEnclosingStmt().getEnclosingStmt*() = if2.getThen() and
3838
se.getEnclosingStmt().getEnclosingStmt*() = sync.getBlock() and
39-
a.(ControlFlowNode).getASuccessor+() = se and
39+
a.getControlFlowNode().getASuccessor+().asExpr() = se and
4040
a.getDest().(FieldAccess).getField() = f
4141
select a,
4242
"Potential race condition. This assignment to $@ is visible to other threads before the subsequent statements are executed.",

java/ql/src/Likely Bugs/Concurrency/LazyInitStaticField.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class ValidSynchStmt extends Stmt {
6464
exists(MethodCall lockAction |
6565
lockAction.getQualifier() = lockField.getAnAccess() and
6666
lockAction.getMethod().getName() = "lock" and
67-
dominates(lockAction, this)
67+
dominates(lockAction.getControlFlowNode(), this.getControlFlowNode())
6868
) and
6969
exists(MethodCall unlockAction |
7070
unlockAction.getQualifier() = lockField.getAnAccess() and
7171
unlockAction.getMethod().getName() = "unlock" and
72-
postDominates(unlockAction, this)
72+
postDominates(unlockAction.getControlFlowNode(), this.getControlFlowNode())
7373
)
7474
)
7575
}

java/ql/src/Likely Bugs/Concurrency/UnreleasedLock.ql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class LockType extends RefType {
5959
}
6060

6161
predicate lockBlock(LockType t, BasicBlock b, int locks) {
62-
locks = strictcount(int i | b.getNode(i) = t.getLockAccess())
62+
locks = strictcount(int i | b.getNode(i).asExpr() = t.getLockAccess())
6363
}
6464

6565
predicate unlockBlock(LockType t, BasicBlock b, int unlocks) {
66-
unlocks = strictcount(int i | b.getNode(i) = t.getUnlockAccess())
66+
unlocks = strictcount(int i | b.getNode(i).asExpr() = t.getUnlockAccess())
6767
}
6868

6969
/**
@@ -90,11 +90,11 @@ predicate failedLock(LockType t, BasicBlock lockblock, BasicBlock exblock) {
9090
exists(ControlFlowNode lock |
9191
lock = lockblock.getLastNode() and
9292
(
93-
lock = t.getLockAccess()
93+
lock.asExpr() = t.getLockAccess()
9494
or
9595
exists(SsaExplicitUpdate lockbool |
9696
// Using the value of `t.getLockAccess()` ensures that it is a `tryLock` call.
97-
lock = lockbool.getAUse() and
97+
lock.asExpr() = lockbool.getAUse() and
9898
lockbool.getDefiningExpr().(VariableAssign).getSource() = t.getLockAccess()
9999
)
100100
) and
@@ -147,12 +147,12 @@ predicate blockIsLocked(LockType t, BasicBlock src, BasicBlock b, int locks) {
147147
)
148148
}
149149

150-
from Callable c, LockType t, BasicBlock src, BasicBlock exit, MethodCall lock
150+
from Callable c, LockType t, BasicBlock src, ExitBlock exit, MethodCall lock
151151
where
152152
// Restrict results to those methods that actually attempt to unlock.
153153
t.getUnlockAccess().getEnclosingCallable() = c and
154154
blockIsLocked(t, src, exit, _) and
155-
exit.getLastNode() = c and
156-
lock = src.getANode() and
155+
exit.getEnclosingCallable() = c and
156+
lock = src.getANode().asExpr() and
157157
lock = t.getLockAccess()
158158
select lock, "This lock might not be unlocked or might be locked more times than it is unlocked."

java/ql/src/Likely Bugs/Termination/ConstantLoopCondition.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ predicate mainLoopCondition(LoopStmt loop, Expr cond) {
6161
else loopReentry = cond
6262
|
6363
last.getEnclosingStmt().getEnclosingStmt*() = loop.getBody() and
64-
last.getASuccessor().(Expr).getParent*() = loopReentry
64+
last.getASuccessor().asExpr().getParent*() = loopReentry
6565
)
6666
}
6767

@@ -75,7 +75,7 @@ where
7575
// None of the ssa variables in `cond` are updated inside the loop.
7676
forex(SsaVariable ssa, VarRead use | ssa.getAUse() = use and use.getParent*() = cond |
7777
not ssa.getCfgNode().getEnclosingStmt().getEnclosingStmt*() = loop or
78-
ssa.getCfgNode().(Expr).getParent*() = loop.(ForStmt).getAnInit()
78+
ssa.getCfgNode().asExpr().getParent*() = loop.(ForStmt).getAnInit()
7979
) and
8080
// And `cond` does not use method calls, field reads, or array reads.
8181
not exists(MethodCall ma | ma.getParent*() = cond) and

java/ql/src/Security/CWE/CWE-833/LockOrderInconsistency.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ predicate badReentrantLockOrder(MethodCall first, MethodCall second, MethodCall
8080
otherSecond = v1.getLockAction() and
8181
second = v2.getLockAction() and
8282
otherFirst = v2.getLockAction() and
83-
first.(ControlFlowNode).getASuccessor+() = second and
84-
otherFirst.(ControlFlowNode).getASuccessor+() = otherSecond
83+
first.getControlFlowNode().getASuccessor+() = second.getControlFlowNode() and
84+
otherFirst.getControlFlowNode().getASuccessor+() = otherSecond.getControlFlowNode()
8585
|
8686
v1 != v2
8787
)

0 commit comments

Comments
 (0)