Skip to content

Commit 5655f8a

Browse files
committed
Ruby: wip fixes
1 parent b34969d commit 5655f8a

3 files changed

Lines changed: 56 additions & 29 deletions

File tree

ruby/ql/lib/codeql/ruby/ast/internal/Synthesis.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ private module AssignOperationDesugar {
833833
)
834834
)
835835
}
836+
837+
final override predicate excludeFromControlFlowTree(AstNode n) {
838+
n = any(ScopeResolutionAssignOperation sao).getLeftOperand()
839+
}
836840
}
837841

838842
/** An assignment operation where the left-hand side is a method call. */

ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ abstract private class ChildMapping extends AstNode {
9393
*/
9494
abstract predicate relevantChild(AstNode child);
9595

96-
pragma[nomagic]
97-
abstract predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb);
98-
96+
// pragma[nomagic]
97+
// abstract predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb);
9998
/**
10099
* Holds if there is a control-flow path from `cfn` to `cfnChild`, where `cfn`
101100
* is a control-flow node for this expression, and `cfnChild` is a control-flow
@@ -105,7 +104,9 @@ abstract private class ChildMapping extends AstNode {
105104
*/
106105
cached
107106
predicate hasCfgChild(AstNode child, CfgNode cfn, CfgNode cfnChild) {
108-
this.reachesBasicBlock(child, cfn, cfnChild.getBasicBlock()) and
107+
this.relevantChild(child) and
108+
cfn.injects(this) and
109+
// this.reachesBasicBlock(child, cfn, cfnChild.getBasicBlock()) and
109110
cfnChild.injects(desugar(child))
110111
}
111112
}
@@ -114,38 +115,37 @@ abstract private class ChildMapping extends AstNode {
114115
* A class for mapping parent-child AST nodes to parent-child CFG nodes.
115116
*/
116117
abstract private class ExprChildMapping extends Expr, ChildMapping {
117-
pragma[nomagic]
118-
override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) {
119-
this.relevantChild(child) and
120-
cfn = this.getAControlFlowNode() and
121-
bb.getANode() = cfn
122-
or
123-
exists(BasicBlock mid |
124-
this.reachesBasicBlock(child, cfn, mid) and
125-
bb = mid.getAPredecessor() and
126-
not mid.getANode().getAstNode() = child
127-
)
128-
}
118+
// pragma[nomagic]
119+
// override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) {
120+
// this.relevantChild(child) and
121+
// cfn = this.getAControlFlowNode() and
122+
// bb.getANode() = cfn
123+
// or
124+
// exists(BasicBlock mid |
125+
// this.reachesBasicBlock(child, cfn, mid) and
126+
// bb = mid.getAPredecessor() and
127+
// not mid.getANode().getAstNode() = child
128+
// )
129+
// }
129130
}
130131

131132
/**
132133
* A class for mapping parent-child AST nodes to parent-child CFG nodes.
133134
*/
134135
abstract private class NonExprChildMapping extends ChildMapping {
135136
NonExprChildMapping() { not this instanceof Expr }
136-
137-
pragma[nomagic]
138-
override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) {
139-
this.relevantChild(child) and
140-
cfn.injects(this) and
141-
bb.getANode() = cfn
142-
or
143-
exists(BasicBlock mid |
144-
this.reachesBasicBlock(child, cfn, mid) and
145-
bb = mid.getASuccessor() and
146-
not mid.getANode().getAstNode() = child
147-
)
148-
}
137+
// pragma[nomagic]
138+
// override predicate reachesBasicBlock(AstNode child, CfgNode cfn, BasicBlock bb) {
139+
// this.relevantChild(child) and
140+
// cfn.injects(this) and
141+
// bb.getANode() = cfn
142+
// or
143+
// exists(BasicBlock mid |
144+
// this.reachesBasicBlock(child, cfn, mid) and
145+
// bb = mid.getASuccessor() and
146+
// not mid.getANode().getAstNode() = child
147+
// )
148+
// }
149149
}
150150

151151
/** Provides classes for control-flow nodes that wrap AST expressions. */

ruby/ql/lib/codeql/ruby/controlflow/ControlFlowGraph2.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ private module Ast implements AstSig<Location> {
8989
index = 1 and pair.getValue() = result
9090
)
9191
or
92+
exists(R::Ast::ArrayPattern arraypattern | parent = arraypattern |
93+
index = -1 and arraypattern.getClass() = result
94+
or
95+
arraypattern.getPrefixElement(index) = result
96+
or
97+
exists(int restix | restix = count(arraypattern.getPrefixElement(_)) |
98+
restix = index and arraypattern.getRestVariableAccess() = result
99+
or
100+
arraypattern.getSuffixElement(index - restix - 1) = result
101+
)
102+
)
103+
or
104+
exists(R::Ast::FindPattern findpattern | parent = findpattern |
105+
index = -2 and findpattern.getClass() = result
106+
or
107+
index = -1 and findpattern.getPrefixVariableAccess() = result
108+
or
109+
findpattern.getElement(index) = result
110+
or
111+
index = 1 + max(int i | exists(findpattern.getElement(i))) and
112+
findpattern.getSuffixVariableAccess() = result
113+
)
114+
or
92115
exists(R::Ast::HashPattern hashpattern | parent = hashpattern |
93116
index = -1 and hashpattern.getClass() = result
94117
or

0 commit comments

Comments
 (0)