Skip to content

Commit e549f15

Browse files
committed
Ruby: fix implicit 'this'
1 parent 056b1e8 commit e549f15

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Node extends TNode {
5656
Node getASuccessor() { localFlowStep(this, result) }
5757

5858
/** Gets the constant value of this expression, if any. */
59-
ConstantValue getConstantValue() { result = asExpr().getExpr().getConstantValue() }
59+
ConstantValue getConstantValue() { result = this.asExpr().getExpr().getConstantValue() }
6060

6161
/**
6262
* Gets the callable corresponding to this block, lambda expression, or call to `proc` or `lambda`.
@@ -160,7 +160,7 @@ class CallNode extends LocalSourceNode, ExprNode {
160160
* ```
161161
*/
162162
class SetterCallNode extends CallNode {
163-
SetterCallNode() { asExpr().getExpr() instanceof SetterMethodCall }
163+
SetterCallNode() { this.asExpr().getExpr() instanceof SetterMethodCall }
164164

165165
/**
166166
* Gets the name of the method being called without the trailing `=`. For example, in the following
@@ -170,7 +170,9 @@ class SetterCallNode extends CallNode {
170170
* foo.value = 1
171171
* ```
172172
*/
173-
final string getTargetName() { result = asExpr().getExpr().(SetterMethodCall).getTargetName() }
173+
final string getTargetName() {
174+
result = this.asExpr().getExpr().(SetterMethodCall).getTargetName()
175+
}
174176
}
175177

176178
/**
@@ -958,32 +960,34 @@ class CallableNode extends ExprNode {
958960
}
959961

960962
/** Gets the `n`th positional parameter. */
961-
ParameterNode getParameter(int n) { getParameterPosition(result).isPositional(n) }
963+
ParameterNode getParameter(int n) { this.getParameterPosition(result).isPositional(n) }
962964

963965
/** Gets the keyword parameter of the given name. */
964-
ParameterNode getKeywordParameter(string name) { getParameterPosition(result).isKeyword(name) }
966+
ParameterNode getKeywordParameter(string name) {
967+
this.getParameterPosition(result).isKeyword(name)
968+
}
965969

966970
/** Gets the `self` parameter of this callable, if any. */
967-
ParameterNode getSelfParameter() { getParameterPosition(result).isSelf() }
971+
ParameterNode getSelfParameter() { this.getParameterPosition(result).isSelf() }
968972

969973
/**
970974
* Gets the `hash-splat` parameter. This is a synthetic parameter holding
971975
* a hash object with entries for each keyword argument passed to the function.
972976
*/
973-
ParameterNode getHashSplatParameter() { getParameterPosition(result).isHashSplat() }
977+
ParameterNode getHashSplatParameter() { this.getParameterPosition(result).isHashSplat() }
974978

975979
/**
976980
* Gets the block parameter of this method, if any.
977981
*/
978-
ParameterNode getBlockParameter() { getParameterPosition(result).isBlock() }
982+
ParameterNode getBlockParameter() { this.getParameterPosition(result).isBlock() }
979983

980984
/**
981985
* Gets a `yield` in this method call or `.call` on the block parameter.
982986
*/
983987
CallNode getABlockCall() {
984-
hasYieldCall(getBlockParameter(), result)
988+
hasYieldCall(this.getBlockParameter(), result)
985989
or
986-
result = getBlockParameter().getAMethodCall("call")
990+
result = this.getBlockParameter().getAMethodCall("call")
987991
}
988992

989993
/**
@@ -1011,7 +1015,7 @@ class MethodNode extends CallableNode {
10111015
MethodBase asMethod() { result = this.asCallableAstNode() }
10121016

10131017
/** Gets the name of this method. */
1014-
string getMethodName() { result = asMethod().getName() }
1018+
string getMethodName() { result = this.asMethod().getName() }
10151019
}
10161020

10171021
/**
@@ -1032,14 +1036,14 @@ class BlockNode extends CallableNode {
10321036
* This node simply provides convenient access to the key and value as data flow nodes.
10331037
*/
10341038
class PairNode extends ExprNode {
1035-
PairNode() { getExprNode() instanceof CfgNodes::ExprNodes::PairCfgNode }
1039+
PairNode() { this.getExprNode() instanceof CfgNodes::ExprNodes::PairCfgNode }
10361040

10371041
/**
10381042
* Holds if this pair is of form `key => value` or `key: value`.
10391043
*/
10401044
predicate hasKeyAndValue(Node key, Node value) {
10411045
exists(CfgNodes::ExprNodes::PairCfgNode n |
1042-
getExprNode() = n and
1046+
this.getExprNode() = n and
10431047
key = TExprNode(n.getKey()) and
10441048
value = TExprNode(n.getValue())
10451049
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private class ActionControllerProtectFromForgeryCall extends CsrfProtectionSetti
523523
}
524524

525525
private string getWithValueText() {
526-
result = getKeywordArgument("with").getConstantValue().getSymbol()
526+
result = this.getKeywordArgument("with").getConstantValue().getSymbol()
527527
}
528528

529529
// Calls without `with: :exception` can allow for bypassing CSRF protection

0 commit comments

Comments
 (0)