Skip to content
Draft
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
28 changes: 18 additions & 10 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1643,16 +1643,24 @@ private module ReturnNodes {
}
}

pragma[noinline]
private AstNode implicitReturn(Callable c, ExprNode n) {
exists(CfgNodes::ExprCfgNode en |
en = n.getExprNode() and
en.getASuccessor().(CfgNodes::AnnotatedExitNode).isNormal() and
n.(NodeImpl).getCfgScope() = c and
result = en.getExpr()
)
private AstNode desugar(AstNode n) {
result = n.getDesugared()
or
not exists(n.getDesugared()) and
result = n
}

private Expr getLast(StmtSequence s) {
result = getLast(s.(BodyStmt).getElse())
or
result = implicitReturn(c, n).getParent()
result = getLast(s.(BodyStmt).getARescue().getBody())
or
not exists(s.(BodyStmt).getElse()) and
exists(Stmt last | last = s.getLastStmt() |
result = getLast(last)
or
result = last and not last instanceof StmtSequence
)
}

/**
Expand All @@ -1661,7 +1669,7 @@ private module ReturnNodes {
* last thing that is evaluated in the body of the callable.
*/
class ExprReturnNode extends SourceReturnNode, ExprNode {
ExprReturnNode() { exists(Callable c | implicitReturn(c, this) = c.getBody().getAStmt()) }
ExprReturnNode() { this.getExprNode().getExpr() = desugar(getLast(any(Callable c).getBody())) }

override ReturnKind getKindSource() {
exists(CfgScope scope | scope = this.(NodeImpl).getCfgScope() |
Expand Down
Loading