Skip to content
Draft
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
3 changes: 3 additions & 0 deletions ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ private predicate completionIsValidForStmt(AstNode n, Completion c) {
or
n instanceof ReturnStmt and
c = TReturnCompletion()
or
n instanceof RetryStmt and
c = TRetryCompletion()
}

private AstNode getARescuableBodyChild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,11 @@ module Trees {
last(super.getBody(), pred, c) and
c instanceof NormalCompletion and
succ = this
or
pred = super.getBody().getAStmt().getAChild*() and
pred instanceof RetryStmt and
c instanceof RetryCompletion and
exists(BodyStmtTree stmt | this = stmt.getARescue() | first(stmt, succ))
}
}

Expand Down
4 changes: 4 additions & 0 deletions ruby/ql/src/queries/variables/UninitializedLocal.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class RelevantLocalVariableReadAccess extends LocalVariableReadAccess {
not exists(MethodCall c |
c.getReceiver() = this and
c.getMethodName() = "nil?"
) and
not exists(BinaryOperation b |
b.getLeftOperand() = this and
b.getOperator() = "||"
)
}
}
Expand Down
7 changes: 6 additions & 1 deletion ruby/ql/src/queries/variables/UnusedParameter.ql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @id rb/unused-parameter
* @tags maintainability
* external/cwe/cwe-563
* quality
* @precision low
*/

Expand All @@ -24,5 +25,9 @@ class RelevantParameterVariable extends LocalVariable {

from RelevantParameterVariable v
where
not exists(Ssa::WriteDefinition def | def.getWriteAccess().getAstNode() = v.getDefiningAccess())
not exists(Ssa::WriteDefinition def | def.getWriteAccess().getAstNode() = v.getDefiningAccess()) and
not exists(SuperCall s | s.getEnclosingCallable().getAParameter().getAVariable() = v |
// a call to 'super' without any arguments will pass on the parameter.
not exists(s.getAnArgument())
)
select v, "The parameter '" + v.getName() + "' is never used."
22 changes: 22 additions & 0 deletions ruby/ql/test/library-tests/controlflow/graph/raise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,25 @@ def m16(b1, b2)
return 3
end
end

def m17(b1, b2)
begin
raise ExceptionA if b1
rescue ExceptionA
if b2
b1 = false
retry
end
end
end

def m18(b2)
b1 = true
begin
raise ExceptionA if b1
rescue ExceptionA
if b2
b1 = false
end
end
end
Loading