Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ module Ast implements AstSig<Location> {

class DoStmt = CS::DoStmt;

class UntilStmt extends LoopStmt {
UntilStmt() { none() }
}

final private class FinalForStmt = CS::ForStmt;

class ForStmt extends FinalForStmt {
Expand Down
4 changes: 4 additions & 0 deletions java/ql/lib/semmle/code/java/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ private module Ast implements AstSig<Location> {

class DoStmt = J::DoStmt;

class UntilStmt extends LoopStmt {
UntilStmt() { none() }
}

final private class FinalForStmt = J::ForStmt;

class ForStmt extends FinalForStmt {
Expand Down
32 changes: 24 additions & 8 deletions shared/controlflow/codeql/controlflow/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ signature module AstSig<LocationSig Location> {
Expr getCondition();
}

/** An `until` loop statement. */
class UntilStmt extends LoopStmt {
/** Gets the boolean condition of this `until` loop. */
Expr getCondition();
Comment on lines +124 to +125
}

/** A traditional C-style `for` loop. */
class ForStmt extends LoopStmt {
/** Gets the initializer of the loop at the specified (zero-based) position, if any. */
Expand Down Expand Up @@ -608,6 +614,7 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
any(IfStmt ifstmt).getCondition() = n or
any(WhileStmt whilestmt).getCondition() = n or
any(DoStmt dostmt).getCondition() = n or
any(UntilStmt untilstmt).getCondition() = n or
any(ForStmt forstmt).getCondition() = n or
any(ConditionalExpr condexpr).getCondition() = n or
any(CatchClause catch).getCondition() = n or
Expand Down Expand Up @@ -1513,7 +1520,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
n2.isBefore(ifstmt.getCondition())
or
n1.isAfterTrue(ifstmt.getCondition()) and
n2.isBefore(ifstmt.getThen())
(
n2.isBefore(ifstmt.getThen())
or
not exists(ifstmt.getThen()) and
n2.isAfter(ifstmt)
Comment on lines +1526 to +1527
)
or
n1.isAfterFalse(ifstmt.getCondition()) and
(
Expand All @@ -1530,26 +1542,30 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
n2.isAfter(ifstmt)
)
or
exists(WhileStmt whilestmt |
n1.isBefore(whilestmt) and
n2.isAdditional(whilestmt, loopHeaderTag())
exists(LoopStmt loopstmt | loopstmt instanceof WhileStmt or loopstmt instanceof UntilStmt |
n1.isBefore(loopstmt) and
n2.isAdditional(loopstmt, loopHeaderTag())
)
or
exists(DoStmt dostmt |
n1.isBefore(dostmt) and
n2.isBefore(dostmt.getBody())
)
or
exists(LoopStmt loopstmt, AstNode cond |
loopstmt.(WhileStmt).getCondition() = cond or loopstmt.(DoStmt).getCondition() = cond
exists(LoopStmt loopstmt, AstNode cond, boolean while |
loopstmt.(WhileStmt).getCondition() = cond and while = true
or
loopstmt.(DoStmt).getCondition() = cond and while = true
or
loopstmt.(UntilStmt).getCondition() = cond and while = false
|
n1.isAdditional(loopstmt, loopHeaderTag()) and
n2.isBefore(cond)
or
n1.isAfterTrue(cond) and
n1.isAfterValue(cond, any(BooleanSuccessor b | b.getValue() = while)) and
n2.isBefore(loopstmt.getBody())
or
n1.isAfterFalse(cond) and
n1.isAfterValue(cond, any(BooleanSuccessor b | b.getValue() = while.booleanNot())) and
n2.isAfter(loopstmt)
or
n1.isAfter(loopstmt.getBody()) and
Expand Down
Loading