Skip to content

Commit 861ae85

Browse files
authored
Merge pull request #7391 from github/ruby/callnode-more-predicates
Ruby: Add `getBlock` and `getNumberOfArguments` predicates to `DataFlow::CallNode`
2 parents c5728b2 + 3262a14 commit 861ae85

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class CallNode extends LocalSourceNode {
6161

6262
/** Gets the name of the the method called by the method call (if any) corresponding to this data-flow node */
6363
string getMethodName() { result = node.getExpr().(MethodCall).getMethodName() }
64+
65+
/** Gets the number of arguments of this call. */
66+
int getNumberOfArguments() { result = node.getNumberOfArguments() }
67+
68+
/** Gets the block of this call. */
69+
Node getBlock() { result.asExpr() = node.getBlock() }
6470
}
6571

6672
/**

ruby/ql/lib/codeql/ruby/frameworks/Rails.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private class ConfigSourceNode extends DataFlow::LocalSourceNode {
6868
configCall = this.asExpr().getExpr()
6969
|
7070
configureCallNode = getAConfigureCallNode() and
71-
block = configureCallNode.asExpr().getExpr().(MethodCall).getBlock() and
71+
block = configureCallNode.getBlock().asExpr().getExpr() and
7272
configCall.getParent+() = block and
7373
configCall.getMethodName() = "config"
7474
)
@@ -84,8 +84,6 @@ private class CallAgainstConfig extends DataFlow::CallNode {
8484
CallAgainstConfig() { this.getReceiver() instanceof ConfigNode }
8585

8686
MethodCall getCall() { result = this.asExpr().getExpr() }
87-
88-
Block getBlock() { result = this.getCall().getBlock() }
8987
}
9088

9189
private class ActionControllerConfigNode extends DataFlow::Node {

ruby/ql/lib/codeql/ruby/frameworks/StandardLibrary.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class KernelMethodCall extends DataFlow::CallNode {
2626
)
2727
)
2828
}
29-
30-
int getNumberOfArguments() { result = methodCall.getNumberOfArguments() }
3129
}
3230

3331
/**

0 commit comments

Comments
 (0)