Skip to content

Commit d00196f

Browse files
authored
Merge pull request #7048 from hvitved/ruby/remove-node-predicates
Ruby: Remove `Node::getEnclosingCallable` and `ParameterNode::isParameterOf`
2 parents 3638892 + 16d96d2 commit d00196f

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) {
450450
*/
451451
predicate exprNodeReturnedFrom(DataFlow::ExprNode e, Callable c) {
452452
exists(ReturningNode r |
453-
r.getEnclosingCallable().asCallable() = c and
453+
nodeGetEnclosingCallable(r).asCallable() = c and
454454
(
455455
r.(ExplicitReturnNode).getReturningNode().getReturnedValueNode() = e.asExpr() or
456456
r.(ExprReturnNode) = e

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ private import SsaImpl as SsaImpl
77
private import FlowSummaryImpl as FlowSummaryImpl
88

99
/** Gets the callable in which this node occurs. */
10-
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
10+
DataFlowCallable nodeGetEnclosingCallable(NodeImpl n) { result = n.getEnclosingCallable() }
1111

1212
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
13-
predicate isParameterNode(ParameterNode p, DataFlowCallable c, int pos) { p.isParameterOf(c, pos) }
13+
predicate isParameterNode(ParameterNodeImpl p, DataFlowCallable c, int pos) {
14+
p.isParameterOf(c, pos)
15+
}
1416

1517
abstract class NodeImpl extends Node {
18+
DataFlowCallable getEnclosingCallable() { result = TCfgScope(this.getCfgScope()) }
19+
1620
/** Do not call: use `getEnclosingCallable()` instead. */
1721
abstract CfgScope getCfgScope();
1822

@@ -312,7 +316,7 @@ private module ParameterNodes {
312316
abstract class ParameterNodeImpl extends ParameterNode, NodeImpl {
313317
abstract predicate isSourceParameterOf(Callable c, int i);
314318

315-
override predicate isParameterOf(DataFlowCallable c, int i) {
319+
predicate isParameterOf(DataFlowCallable c, int i) {
316320
this.isSourceParameterOf(c.asCallable(), i)
317321
}
318322
}
@@ -802,7 +806,7 @@ predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
802806
)
803807
or
804808
receiver = call.(SummaryCall).getReceiver() and
805-
if receiver.(ParameterNode).isParameterOf(_, -2)
809+
if receiver.(ParameterNodeImpl).isParameterOf(_, -2)
806810
then kind = TYieldCallKind()
807811
else kind = TLambdaCallKind()
808812
}

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Node extends TNode {
2525
// TODO: cache
2626
final Location getLocation() { result = this.(NodeImpl).getLocationImpl() }
2727

28-
DataFlowCallable getEnclosingCallable() { result = TCfgScope(this.(NodeImpl).getCfgScope()) }
29-
3028
/**
3129
* Holds if this element is at the specified location.
3230
* The location spans column `startcolumn` of line `startline` to
@@ -85,12 +83,6 @@ class ExprNode extends Node, TExprNode {
8583
class ParameterNode extends Node, TParameterNode {
8684
/** Gets the parameter corresponding to this node, if any. */
8785
Parameter getParameter() { none() }
88-
89-
/**
90-
* Holds if this node is the parameter of callable `c` at the specified
91-
* (zero-based) position.
92-
*/
93-
predicate isParameterOf(DataFlowCallable c, int i) { none() }
9486
}
9587

9688
/**

ruby/ql/lib/codeql/ruby/security/UrlRedirectCustomizations.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ module UrlRedirect {
5757
this = e.getRedirectLocation() and
5858
// As a rough heuristic, assume that methods with these names are handlers for POST/PUT/PATCH/DELETE requests,
5959
// which are not as vulnerable to URL redirection because browsers will not initiate them from clicking a link.
60-
not this.getEnclosingCallable()
61-
.asCallable()
62-
.(Method)
60+
not this.asExpr()
61+
.getExpr()
62+
.getEnclosingMethod()
6363
.getName()
6464
.regexpMatch(".*(create|update|destroy).*")
6565
)

0 commit comments

Comments
 (0)